From f7289e29771d575df053cd754d44c2dab72c6dec Mon Sep 17 00:00:00 2001 From: Anindya Roy <104991338+gitofanindya@users.noreply.github.com> Date: Thu, 20 Apr 2023 21:47:29 +0530 Subject: [PATCH] NXDRIVE-2830: Do not rename locally when a new account is added (#3905) * NXDRIVE-2800: Do not rename locally when the document is updated --- docs/changes/5.3.1.md | 1 + nxdrive/engine/watcher/remote_watcher.py | 2 + tests/functional/test_remote_watcher.py | 88 ++++++++++++++++++++++++ 3 files changed, 91 insertions(+) diff --git a/docs/changes/5.3.1.md b/docs/changes/5.3.1.md index 4725184021..b11d767492 100644 --- a/docs/changes/5.3.1.md +++ b/docs/changes/5.3.1.md @@ -7,6 +7,7 @@ Release date: `2023-xx-xx` - [NXDRIVE-2772](https://jira.nuxeo.com/browse/NXDRIVE-2772): Sync icons disappear after restart - [NXDRIVE-2801](https://jira.nuxeo.com/browse/NXDRIVE-2801): Do not prefix synchronized folder name with ancestors when there is no duplicated root - [NXDRIVE-2800](https://jira.nuxeo.com/browse/NXDRIVE-2800): Do not rename locally when the document is updated +- [NXDRIVE-2830](https://jira.nuxeo.com/browse/NXDRIVE-2830): Do not rename locally when a new account is added - [NXDRIVE-2764](https://jira.nuxeo.com/browse/NXDRIVE-2764): Fix handling of special and non-English characters in document names ### Direct Edit diff --git a/nxdrive/engine/watcher/remote_watcher.py b/nxdrive/engine/watcher/remote_watcher.py index fd116b67b1..7e88b2a3c5 100644 --- a/nxdrive/engine/watcher/remote_watcher.py +++ b/nxdrive/engine/watcher/remote_watcher.py @@ -399,6 +399,8 @@ def _scan_remote_recursive( continue log.debug(f"Scanning remote child: {child_info!r}") + if WORKSPACE_ROOT in child_info.uid: + child_info = self.engine.remote.expand_sync_root_name(child_info) new_pair = False child_pair = None if child_info.uid in children: diff --git a/tests/functional/test_remote_watcher.py b/tests/functional/test_remote_watcher.py index d7378a1a83..407a36bf72 100644 --- a/tests/functional/test_remote_watcher.py +++ b/tests/functional/test_remote_watcher.py @@ -2,6 +2,7 @@ from unittest.mock import patch from nxdrive.engine.watcher.remote_watcher import RemoteWatcher +from nxdrive.objects import RemoteFileInfo def test_sync_root_name(manager_factory): @@ -23,6 +24,9 @@ def test_sync_root_name(manager_factory): "", ), ) + + remote_path = "/org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory#" + test_watcher = RemoteWatcher(engine, dao) def get_changes(): @@ -59,6 +63,12 @@ def get_changes(): 51b7841d648-test" }' ) + def init_scan_remote(doc_pair, remote_info): + return remote_path + + def get_children(arg): + return [] + def get_states_from_remote_(path): return [docpair] @@ -80,6 +90,84 @@ def _find_remote_child_match_or_create_(parent_pair, new_info): update_remote_states = test_watcher._update_remote_states + scan_remote = test_watcher._scan_remote_recursive + + with patch.object(test_watcher, "_get_changes", new=get_changes): + info = update_remote_states + + assert info is not None + + remote_info = RemoteFileInfo.from_dict( + eval( + '{"id": "defaultSyncRootFolderItemFactory#default\ + #a7e4ce2a-e4a7-432a-b5e1-62b354606929-test",\ + "parentId": "org.nuxeo.drive.service.impl.\ + DefaultTopLevelFolderItemFactory#",\ + "name": "ROY",\ + "folder": True,\ + "creator": "Administrator",\ + "lastContributor": "Administrator",\ + "creationDate": 1681875486061,\ + "lastModificationDate": 1681875528408,\ + "canRename": True,\ + "canDelete": True,\ + "lockInfo": None,\ + "path": "/org.nuxeo.drive.service.\ + impl.DefaultTopLevelFolderItemFactory\ + #/defaultSyncRootFolderItemFactory#default\ + #a7e4ce2a-e4a7-432a-b5e1-62b354606929-test",\ + "userName": "Administrator",\ + "canCreateChild": True,\ + "canScrollDescendants": True\ + }' + ) + ) + + def get_fs_children_(*args): + return [remote_info] + + def interact(): + return + + def do_scan_remote(*args, **kwargs): + return + + def add_scanned(path): + assert path == remote_path + + def find_remote_child_match_or_create(*args): + return ( + namedtuple( + "DocPair", + "local_path, local_parent_path, remote_ref, local_state, remote_state, pair_state, last_error", + defaults=( + ".", + ".", + "org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory#", + "synchronized", + "synchronized", + "synchronized", + None, + ), + ), + True, + ) + + with patch.object(test_watcher, "_init_scan_remote", new=init_scan_remote): + with patch.object(test_watcher, "_interact", new=interact): + with patch.object( + test_watcher, + "_find_remote_child_match_or_create", + new=find_remote_child_match_or_create, + ): + with patch.object(test_watcher, "_do_scan_remote", new=do_scan_remote): + with patch.object(dao, "add_path_scanned", new=add_scanned): + with patch.object(dao, "get_remote_children", new=get_children): + with patch.object( + engine.remote, "get_fs_children", new=get_fs_children_ + ): + scan_remote(docpair, remote_info) + with patch.object(test_watcher, "_get_changes", new=get_changes): with patch.object(test_watcher, "_force_remote_scan", new=_force_remote_scan_): with patch.object(