Patchwork [bitbake-devel] fetch2: handle broken symlinks in local mirror handling

login
register
mail settings
Submitter Christopher Larson
Date July 31, 2012, 10:20 p.m.
Message ID <1343773214-29621-1-git-send-email-kergoth@gmail.com>
Download mbox | patch
Permalink /patch/33469/
State Accepted
Commit 229ed3857e826e3e215e843cb51f729c1e13ed37
Headers show

Comments

Christopher Larson - July 31, 2012, 10:20 p.m.
From: Christopher Larson <chris_larson@mentor.com>

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.

Signed-off-by: Christopher Larson <chris_larson@mentor.com>
---
 lib/bb/fetch2/__init__.py |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Richard Purdie - Aug. 2, 2012, 4:05 p.m.
On Tue, 2012-07-31 at 15:20 -0700, Christopher Larson wrote:
> From: Christopher Larson <chris_larson@mentor.com>
> 
> 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.
> 
> Signed-off-by: Christopher Larson <chris_larson@mentor.com>
> ---
>  lib/bb/fetch2/__init__.py |    6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)

Merged to master, thanks.

Richard

Patch

diff --git a/lib/bb/fetch2/__init__.py b/lib/bb/fetch2/__init__.py
index fa963be..8f5b097 100644
--- a/lib/bb/fetch2/__init__.py
+++ b/lib/bb/fetch2/__init__.py
@@ -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