Commits

Erik Schweller  committed b55c6a2

don't keep paths 'below' the structure we are copying with the no_change rule, update test

  • Participants
  • Parent commits 6c7fd22

Comments (0)

Files changed (2)

File dedupe_copy/dedupe_copy.py

 
 
 def _path_rules_parser(rules, dest_dir, extension, mtime_str, size,
-    source_dirs, src):
+    source_dirs, src, read_paths):
     """Builds a path based on the path rules for the given extension pattern"""
     rule_list = rules.get(_best_match(rules.keys(), extension), ['no_change'])
+    dest = None
     for rule in rule_list:
         if rule == 'mtime':
             dest_dir = os.path.join(dest_dir, mtime_str)
         elif rule == 'extension':
             dest_dir = os.path.join(dest_dir, extension)
         elif rule == 'no_change':
+            # remove the path up to our source_dirs from src so we don't
+            # preserve the structure "below" where our copy is from
+            for p in read_paths:
+                if source_dirs.startswith(p):
+                    source_dirs = source_dirs.replace(p, '', 1)
+            if source_dirs.startswith(os.sep):
+                source_dirs = source_dirs[1:]
             dest_dir = os.path.join(dest_dir, source_dirs)
-    dest = os.path.join(dest_dir, src)
+    if dest is None:
+        dest = os.path.join(dest_dir, src)
     return dest, dest_dir
 
 
                 if self.path_rules is not None:
                     source_dirs = os.path.dirname(src)
                     _, source_dirs = os.path.splitdrive(source_dirs)
-                    if source_dirs.startswith(os.sep):
-                        source_dirs = source_dirs[1:]
                     dest, dest_dir = self.path_rules(self.target_path, ext,
-                        mtime, size, source_dirs, os.path.basename(src))
+                        mtime, size, source_dirs, os.path.basename(src),
+                        self.read_paths)
                 else:
                     dest = os.path.join(self.target_path, ext, mtime,
                         os.path.basename(src))

File dedupe_copy/test/test_copy.py

         # perform the copy
         do_copy(read_from_path=self.temp_dir, copy_to_path=copy_to_path,
             path_rules=['*:no_change'])
-        # the abspath is preserved when copying into a new target
-        copy_to_path = os.path.join(copy_to_path, self.temp_dir)
         # verify we didn't alter the existing data
         result, notes = utils.verify_files(self.file_data)
         self.assertTrue(result, 'Altered original files: {0}'.format(notes))