From eceeb1b1f5edb0f42e690bffdf81828abd8ea7fe Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Sun, 25 Sep 2016 18:24:27 -0700 Subject: Support broken symlinks when cleaning obsolete paths When there's a symlink to a directory, os.walk still lists the symlink in dirs, even if it isn't configured to follow symlinks. This will fail the listdirs check if the symlink is broken (either before or during the cleanup). So instead, check for directory symlinks and remove them using os.remove. Bug: Issue 231 Change-Id: I0ec45a26be566613a4a39bf694a3d9c6328481c2 --- subcmds/sync.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'subcmds/sync.py') diff --git a/subcmds/sync.py b/subcmds/sync.py index cc0b17e9..7ba9ebfc 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -487,7 +487,13 @@ later is required to fix a server side protocol bug. dirs_to_remove += [os.path.join(root, d) for d in dirs if os.path.join(root, d) not in dirs_to_remove] for d in reversed(dirs_to_remove): - if len(os.listdir(d)) == 0: + if os.path.islink(d): + try: + os.remove(d) + except OSError: + print('Failed to remove %s' % os.path.join(root, d), file=sys.stderr) + failed = True + elif len(os.listdir(d)) == 0: try: os.rmdir(d) except OSError: -- cgit v1.2.3-54-g00ecf