summaryrefslogtreecommitdiffstats
path: root/subcmds/sync.py
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2016-09-25 18:24:27 -0700
committerDavid Pursehouse <dpursehouse@collab.net>2016-09-27 03:05:11 +0000
commiteceeb1b1f5edb0f42e690bffdf81828abd8ea7fe (patch)
tree3fd305d999c46951092958f8f675ba67bdd7816a /subcmds/sync.py
parent16889ba43da81aead6bdb3acd1233381dd8e7562 (diff)
downloadgit-repo-eceeb1b1f5edb0f42e690bffdf81828abd8ea7fe.tar.gz
Support broken symlinks when cleaning obsolete pathsv1.12.37
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
Diffstat (limited to 'subcmds/sync.py')
-rw-r--r--subcmds/sync.py8
1 files changed, 7 insertions, 1 deletions
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.
487 dirs_to_remove += [os.path.join(root, d) for d in dirs 487 dirs_to_remove += [os.path.join(root, d) for d in dirs
488 if os.path.join(root, d) not in dirs_to_remove] 488 if os.path.join(root, d) not in dirs_to_remove]
489 for d in reversed(dirs_to_remove): 489 for d in reversed(dirs_to_remove):
490 if len(os.listdir(d)) == 0: 490 if os.path.islink(d):
491 try:
492 os.remove(d)
493 except OSError:
494 print('Failed to remove %s' % os.path.join(root, d), file=sys.stderr)
495 failed = True
496 elif len(os.listdir(d)) == 0:
491 try: 497 try:
492 os.rmdir(d) 498 os.rmdir(d)
493 except OSError: 499 except OSError: