diff --git a/core/app.py b/core/app.py index eb25948a..0345622a 100644 --- a/core/app.py +++ b/core/app.py @@ -94,7 +94,8 @@ class DupeGuru(RegistrableApplication, Broadcaster): def _get_file(self, str_path): path = Path(str_path) - f = fs.get_file(path, self.directories.fileclasses) + # We add fs.Folder to fileclasses in case the file we're loading contains folder paths. + f = fs.get_file(path, self.directories.fileclasses + [fs.Folder]) if f is None: return None try: @@ -197,12 +198,7 @@ class DupeGuru(RegistrableApplication, Broadcaster): while delete_if_empty(path, ['.DS_Store']): path = path[:-1] - def copy_or_move(self, dupe, copy, destination, dest_type): - """ - copy: True = Copy False = Move - destination: string. - dest_type: DestType constants - """ + def copy_or_move(self, dupe, copy: bool, destination: str, dest_type: DestType): source_path = dupe.path location_path = first(p for p in self.directories if dupe.path in p) dest_path = Path(destination) @@ -214,6 +210,9 @@ class DupeGuru(RegistrableApplication, Broadcaster): dest_path = dest_path + source_base if not io.exists(dest_path): io.makedirs(dest_path) + # Add filename to dest_path. For file move/copy, it's not required, but for folders, yes. + dest_path = dest_path + source_path[-1] + logging.debug("Copy/Move operation from '%s' to '%s'", source_path, dest_path) # Raises an EnvironmentError if there's a problem if copy: smart_copy(source_path, dest_path) diff --git a/core/fs.py b/core/fs.py index d81858be..35830f49 100644 --- a/core/fs.py +++ b/core/fs.py @@ -192,6 +192,10 @@ class Folder(File): self._subfolders = [Folder(p) for p in subfolders] return self._subfolders + @classmethod + def can_handle(cls, path): + return not io.islink(path) and io.isdir(path) + def get_file(path, fileclasses=[File]): for fileclass in fileclasses: diff --git a/core/tests/app_test.py b/core/tests/app_test.py index 0ad75868..dd211b79 100644 --- a/core/tests/app_test.py +++ b/core/tests/app_test.py @@ -91,8 +91,8 @@ class TestCaseDupeGuru: dgapp.copy_or_move(f, True, 'some_destination', 0) eq_(1, len(hscommon.conflict.smart_copy.calls)) call = hscommon.conflict.smart_copy.calls[0] - eq_('some_destination', call['dest_path']) - eq_(f.path, call['source_path']) + eq_(call['dest_path'], op.join('some_destination', 'foo')) + eq_(call['source_path'], f.path) def test_copy_or_move_clean_empty_dirs(self, tmpdir, monkeypatch): tmppath = Path(str(tmpdir))