1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2024-11-04 15:29:02 +00:00

Fixed copying operations for folders which didn't work.

This commit is contained in:
Virgil Dupras 2011-04-14 12:55:50 +02:00
parent d887cd118c
commit 0b20b35ffb
3 changed files with 12 additions and 9 deletions

View File

@ -94,7 +94,8 @@ class DupeGuru(RegistrableApplication, Broadcaster):
def _get_file(self, str_path): def _get_file(self, str_path):
path = Path(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: if f is None:
return None return None
try: try:
@ -197,12 +198,7 @@ class DupeGuru(RegistrableApplication, Broadcaster):
while delete_if_empty(path, ['.DS_Store']): while delete_if_empty(path, ['.DS_Store']):
path = path[:-1] path = path[:-1]
def copy_or_move(self, dupe, copy, destination, dest_type): def copy_or_move(self, dupe, copy: bool, destination: str, dest_type: DestType):
"""
copy: True = Copy False = Move
destination: string.
dest_type: DestType constants
"""
source_path = dupe.path source_path = dupe.path
location_path = first(p for p in self.directories if dupe.path in p) location_path = first(p for p in self.directories if dupe.path in p)
dest_path = Path(destination) dest_path = Path(destination)
@ -214,6 +210,9 @@ class DupeGuru(RegistrableApplication, Broadcaster):
dest_path = dest_path + source_base dest_path = dest_path + source_base
if not io.exists(dest_path): if not io.exists(dest_path):
io.makedirs(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 # Raises an EnvironmentError if there's a problem
if copy: if copy:
smart_copy(source_path, dest_path) smart_copy(source_path, dest_path)

View File

@ -192,6 +192,10 @@ class Folder(File):
self._subfolders = [Folder(p) for p in subfolders] self._subfolders = [Folder(p) for p in subfolders]
return self._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]): def get_file(path, fileclasses=[File]):
for fileclass in fileclasses: for fileclass in fileclasses:

View File

@ -91,8 +91,8 @@ class TestCaseDupeGuru:
dgapp.copy_or_move(f, True, 'some_destination', 0) dgapp.copy_or_move(f, True, 'some_destination', 0)
eq_(1, len(hscommon.conflict.smart_copy.calls)) eq_(1, len(hscommon.conflict.smart_copy.calls))
call = hscommon.conflict.smart_copy.calls[0] call = hscommon.conflict.smart_copy.calls[0]
eq_('some_destination', call['dest_path']) eq_(call['dest_path'], op.join('some_destination', 'foo'))
eq_(f.path, call['source_path']) eq_(call['source_path'], f.path)
def test_copy_or_move_clean_empty_dirs(self, tmpdir, monkeypatch): def test_copy_or_move_clean_empty_dirs(self, tmpdir, monkeypatch):
tmppath = Path(str(tmpdir)) tmppath = Path(str(tmpdir))