1
0
mirror of https://github.com/arsenetar/dupeguru.git synced 2025-03-10 05:34:36 +00:00

[#148 state:fixed] Fixed a crash on copy/move when windows drive letters were involved.

This commit is contained in:
Virgil Dupras 2011-03-06 17:21:42 +01:00
parent 6e60ea6984
commit fb3d3a135d

View File

@ -35,6 +35,11 @@ DEBUG_MODE_PREFERENCE = 'DebugMode'
class NoScannableFileError(Exception): class NoScannableFileError(Exception):
pass pass
class DestType:
Direct = 0
Relative = 1
Absolute = 2
class DupeGuru(RegistrableApplication, Broadcaster): class DupeGuru(RegistrableApplication, Broadcaster):
def __init__(self, data_module, appdata): def __init__(self, data_module, appdata):
if self.get_default(DEBUG_MODE_PREFERENCE, False): if self.get_default(DEBUG_MODE_PREFERENCE, False):
@ -107,8 +112,10 @@ class DupeGuru(RegistrableApplication, Broadcaster):
# Must be called by subclasses when they detect that an async job is completed. # Must be called by subclasses when they detect that an async job is completed.
if jobid == JOB_SCAN: if jobid == JOB_SCAN:
self._results_changed() self._results_changed()
elif jobid in (JOB_LOAD, JOB_MOVE, JOB_DELETE): elif jobid in {JOB_LOAD, JOB_MOVE, JOB_DELETE}:
self._results_changed() self._results_changed()
if jobid in {JOB_COPY, JOB_MOVE, JOB_DELETE}:
self.notify('problems_changed') self.notify('problems_changed')
@staticmethod @staticmethod
@ -194,17 +201,17 @@ class DupeGuru(RegistrableApplication, Broadcaster):
""" """
copy: True = Copy False = Move copy: True = Copy False = Move
destination: string. destination: string.
dest_type: 0 = right in destination. dest_type: DestType constants
1 = relative re-creation.
2 = absolute re-creation.
""" """
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)
if dest_type == 2: if dest_type in {DestType.Relative, DestType.Absolute}:
dest_path = dest_path + source_path[1:-1] #Remove drive letter and filename # no filename, no windows drive letter
elif dest_type == 1: source_base = source_path.remove_drive_letter()[:-1]
dest_path = dest_path + source_path[location_path:-1] if dest_type == DestType.Relative:
source_base = source_base[location_path:]
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)
# Raises an EnvironmentError if there's a problem # Raises an EnvironmentError if there's a problem