Skip to content

fix(syncer): [issue #42] Remove redundant path slices in file paths and ancestor root #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

j-archit
Copy link

Removes possibly redundant path and ancestor root slicing as mentioned in #42.

Test results:
Before
image

After
image

Copy link
Owner

@tkhyn tkhyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the PR and sorry for the very late review. See my comments below!

@@ -158,9 +158,9 @@ def _compare(self, dir1, dir2):

if add_path:
left.add(path)
anc_dirs = re_path[:-1].split('/')
anc_dirs = re_path.split('/')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really can't remember why the [:-1] was added here. This dates from when I completely rewrote / adapted dirsync from the original author's code. It was possibly to remove the trailing slash for directories, and I may never have hit this line with re_path being a file. However, to safe-guard against adding too many items to left, shouldn't we either use re_path.rstrip("/").split("/") or add a if not ad: continue in the for loop that follows?

anc_dirs_path = ''
for ad in anc_dirs[1:]:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we have to strip the root directory as we don't want it to appear in the left list. Same, this dates from when the module was completely rewritten back in 2014 and it looks like I did not write enough comments! Does stripping the root create issues? If yes, I would be happy to see a failing test case added to the test suite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants