Skip to content

Commit

Permalink
Merge pull request #115 from ssdi-drive/fix-NXDRIVE-673-Drive-stops-d…
Browse files Browse the repository at this point in the history
…own-sync-on-share-and-move-operation

NXDRIVE-673: Check condition to detect move folder operation on folde…
  • Loading branch information
loopingz authored Dec 21, 2016
2 parents a2aead2 + 070f355 commit 230710b
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 6 deletions.
16 changes: 10 additions & 6 deletions nuxeo-drive-client/nxdrive/engine/watcher/remote_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,16 @@ def _scan_pair(self, remote_path):
return
local_path = path_join(parent_pair.local_path, safe_filename(child_info.name))
remote_parent_path = parent_pair.remote_parent_path + '/' + parent_pair.remote_ref
row_id = self._dao.insert_remote_state(child_info, remote_parent_path, local_path, parent_pair.local_path)
doc_pair = self._dao.get_state_from_id(row_id, from_write=True)
if child_info.folderish:
log.debug("Remote scan_pair: %s", doc_pair.local_path)
self._do_scan_remote(doc_pair, child_info)
log.debug("Remote scan_pair ended: %s", doc_pair.local_path)
if os.path.dirname(child_info.path) == remote_parent_path:
row_id = self._dao.insert_remote_state(child_info, remote_parent_path, local_path, parent_pair.local_path)
doc_pair = self._dao.get_state_from_id(row_id, from_write=True)
if child_info.folderish:
log.debug("Remote scan_pair: %s", doc_pair.local_path)
self._do_scan_remote(doc_pair, child_info)
log.debug("Remote scan_pair ended: %s", doc_pair.local_path)
else:
log.debug("Remote scan_pair: %s is not available, Do full scan", remote_path)
self._scan_remote()

def _check_modified(self, child_pair, child_info):
if child_pair.remote_can_delete != child_info.can_delete:
Expand Down
138 changes: 138 additions & 0 deletions nuxeo-drive-client/nxdrive/tests/test_local_share_move_folders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import os
import shutil
import random
from mock import patch
from nxdrive.engine.watcher.remote_watcher import RemoteWatcher
from nxdrive.tests.common_unit_test import UnitTestCase
from nxdrive.tests.common_unit_test import log

wait_for_security_update = False
src = None
dst = None
original_get_changes = RemoteWatcher._get_changes

def mock_get_changes(self, *args, **kwargs):
global wait_for_security_update
global src
global dst
if wait_for_security_update == True:
summary = original_get_changes(self, *args, **kwargs)
for event in summary['fileSystemChanges']:
if event['eventId'] == 'securityUpdated':
shutil.move(src, dst)
return summary
return original_get_changes(self, *args, **kwargs)

class TestLocalShareMoveFolders(UnitTestCase):

NUMBER_OF_LOCAL_IMAGE_FILES = 10
FILE_NAME_PATTERN = 'file%03d.%s'

def setUp(self):
"""
1. Create folder a1 in Nuxeo Drive Test Workspace sycn root
2. Create folder a2 in Nuxeo Drive Test Workspace sycn root
3. Add 10 image files in a1
"""
self.engine_1.start()
self.wait_sync(wait_for_async=True)
self.engine_1.stop()

# Create a1 and a2
self.folder_path_1 = self.local_client_1.make_folder(u'/', u'a1')
self.folder_path_2 = self.local_client_1.make_folder(u'/', u'a2')

# Add image files to a1
abs_folder_path_1 = self.local_client_1._abspath(self.folder_path_1)
for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1):
file_name = self.FILE_NAME_PATTERN % (file_num, 'jpg')
file_path = os.path.join(abs_folder_path_1, file_name)
self.generate_random_jpg(file_path, random.randint(1000, 3000))
log.debug('Local test files created in a1')

self.engine_1.start()
self.wait_sync(timeout=60, wait_win=True)

# Check local files in a1
self.assertTrue(self.local_client_1.exists('/a1'))
children_1 = [child.name for child in self.local_client_1.get_children_info('/a1')]
self.assertEqual(len(children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES,
'Number of local files (%d) in a1 is different from original (%d)' %
(len(children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES))
self.assertEqual(set(children_1), set(['file%03d.jpg' % file_num
for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1)]))

# Check remote files in a1
a1_remote_id = self.local_client_1.get_remote_id('/a1')
self.assertIsNotNone(a1_remote_id)
log.debug("Remote ref of a1: %s", a1_remote_id)
self.assertTrue(self.remote_file_system_client_1.exists(a1_remote_id))

remote_children_1 = [child.name for child in self.remote_file_system_client_1.get_children_info(a1_remote_id)]
self.assertEqual(len(remote_children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES,
'Number of remote files (%d) in a1 is different from original (%d)' %
(len(remote_children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES))
self.assertEqual(set(remote_children_1), set(['file%03d.jpg' % file_num
for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1)]))
@patch.object(RemoteWatcher, '_get_changes', mock_get_changes)
def test_local_share_move_folder_with_files(self):
global wait_for_security_update
admin_remote_client = self.root_remote_client

global src
src = self.local_client_1._abspath(self.folder_path_1)

global dst
dst = self.local_client_1._abspath(self.folder_path_2)

wait_for_security_update = True
op_input = self.local_client_1.get_remote_id('/a1').split('#')[-1]
admin_remote_client.execute("Document.AddPermission",
url = admin_remote_client.rest_api_url + 'automation/Document.AddPermission',
op_input=op_input,
username=self.user_2,
permission="Everything",
grant="true")

self.wait_sync(enforce_errors=True)

wait_for_security_update = False

# Sync after move operation
self.wait_sync(enforce_errors=True)
# Check that a1 doesn't exist anymore locally
self.assertFalse(self.local_client_1.exists('/a1'))

# Check local files in a2/a1
self.assertTrue(self.local_client_1.exists('/a2/a1'))
children_1 = [child.name for child in self.local_client_1.get_children_info('/a2/a1')]
self.assertEqual(len(children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES,
'Number of local files (%d) in a1 is different from original (%d)' %
(len(children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES))
self.assertEqual(set(children_1), set(['file%03d.jpg' % file_num
for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1)]))

# Check that a1 doesn't exist anymore remotely
self.assertEqual(len(self.remote_document_client_1.get_children_info(self.workspace)), 1)


# Check remote files in a2/a1
a1_remote_id = self.local_client_1.get_remote_id('/a2/a1')
self.assertIsNotNone(a1_remote_id)
log.debug("Remote ref of a1: %s", a1_remote_id)
self.assertTrue(self.remote_file_system_client_1.exists(a1_remote_id))

remote_children_1 = [child.name for child in self.remote_file_system_client_1.get_children_info(a1_remote_id)]
self.assertEqual(len(remote_children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES,
'Number of remote files (%d) in a1 is different from original (%d)' %
(len(remote_children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES))
self.assertEqual(set(remote_children_1), set(['file%03d.jpg' % file_num
for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1)]))

# As Admin create a folder inside a1
parent_folder_uid = admin_remote_client.make_folder(a1_remote_id.split('#')[-1], 'inside_a1')

self.wait_sync(fail_if_timeout=True)

# Check that a1 doesn't exist anymore locally
self.assertTrue(self.local_client_1.exists('/a2/a1/inside_a1'))

0 comments on commit 230710b

Please sign in to comment.