Skip to contentSkip to conversation

fetch2: handle broken symlinks in local mirror handling

PATCH Applied Christopher Larson 2 participants 2 messages Jul 31, 2012 – Aug 2, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fetch2: handle broken symlinks in local mirror handling

From: Christopher Larson <[email protected]>

If a file:// mirror is being used, the fetcher will create a symlink to the local file. However, if the local file gets removed, that link will be dead, and os.path.exists() returns False in that case, so it tries and fails to recreate the link. Now we unlink such a dead link if it exists.

---
 lib/bb/fetch2/__init__.py |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
lib/bb/fetch2/__init__.py +5 -1
index fa963be..8f5b097 100644
@@ -557,7 +557,11 @@ def try_mirror_url(newuri, origud, ud, ld, check = False):
             return None
         # Otherwise the result is a local file:// and we symlink to it
         if not os.path.exists(origud.localpath):
-             os.symlink(ud.localpath, origud.localpath)
+            if os.path.islink(origud.localpath):
+                # Broken symbolic link
+                os.unlink(origud.localpath)
+
+            os.symlink(ud.localpath, origud.localpath)
         update_stamp(newuri, origud, ld)
         return ud.localpath
 
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 11 lines · Christopher Larson

From: Christopher Larson <[email protected]>

If a file:// mirror is being used, the fetcher will create a symlink to the local file. However, if the local file gets removed, that link will be dead, and os.path.exists() returns False in that case, so it tries and fails to recreate the link. Now we unlink such a dead link if it exists.

---
 lib/bb/fetch2/__init__.py |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Merged to master, thanks.

Richard