-
Notifications
You must be signed in to change notification settings - Fork 34
Description
If you use the --diff option to compare directories, it outputs the filenames "Only in dir1" twice, once correctly and then again but without the directory path and the filename has its last character missing.
Example
On Windows 10 using Python 3.9.1.
dir1
| file101.txt
| file102.txt
| file103.txt
|
+---sub1
| file004.txt
| file005.txt
|
\---sub2
file-noextension
file006.txt
file007.txt
dir2
| file010.txt
| file011.txt
| file103.txt
|
+---sub1
| file004.txt
| file005.txt
|
\---sub3
file020.txt
dirsync dir1 dir2 --diff
Difference of directory dir2 from dir1
Only in dir1
**WRONG>> file-noextensio
**WRONG>> file004.tx
**WRONG>> file005.tx
**WRONG>> file006.tx
**WRONG>> file007.tx
>> file101.txt
>> file102.txt
>> sub2
>> sub2\file-noextension
>> sub2\file006.txt
>> sub2\file007.txt
Only in dir2
<< file010.txt
<< file011.txt
<< sub3
<< sub3\file020.txt
Common to dir1 and dir2
-- file103.txt
-- sub1
-- sub1\file004.txt
-- sub1\file005.txt
dirsync finished in 0.00 seconds.
4 directories parsed, 0 files copied
Where the problem is:
In dirsync 2.2.5, syncer.py, lines 159-165.
159 if add_path:
160 left.add(path)
161 anc_dirs = re_path[:-1].split('/')
162 anc_dirs_path = ''
163 for ad in anc_dirs[1:]:
164 anc_dirs_path = os.path.join(anc_dirs_path, ad)
165 left.add(anc_dirs_path)
Line 161: anc_dirs = re_path[:-1].split('/')
strips off the last character of the filename file004.txt -> file004.tx
Perhaps it should be just re_path.split('/')
And the loop lines 163-165 with left.add(anc_dirs_path) adds the unnecessary files to the list left (all with their last character missing).
I really can't see what this loop with anc_dirs_path does. If lines 161-165 are simply removed, the program would seem to do the right thing. Maybe I've missed some important use case, but it's certainly wrong for the example above.