From e15a679924abdabce5b2a9ebbb3247841fb57ac2 Mon Sep 17 00:00:00 2001 From: Roman Savchenko Date: Fri, 17 Oct 2014 11:01:46 +0300 Subject: [PATCH] add safe_symlink to catch existing file and broken link case --- lib/bb/fetch2/__init__.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/bb/fetch2/__init__.py b/lib/bb/fetch2/__init__.py index c0a4763a8b..3b4a0db598 100644 --- a/lib/bb/fetch2/__init__.py +++ b/lib/bb/fetch2/__init__.py @@ -790,6 +790,13 @@ def rename_bad_checksum(ud, suffix): bb.warn("Renaming %s to %s" % (ud.localpath, new_localpath)) bb.utils.movefile(ud.localpath, new_localpath) +def safe_symlink(source, link_name): + if not os.path.exists(link_name): + if os.path.islink(link_name): + os.unlink(link_name) + + os.symlink(source, link_name) + return def try_mirror_url(origud, ud, ld, check = False): # Return of None or a value means we're finished @@ -821,21 +828,18 @@ def try_mirror_url(origud, ud, ld, check = False): and os.path.basename(ud.localpath) != os.path.basename(origud.localpath): bb.utils.mkdirhier(os.path.dirname(ud.donestamp)) open(ud.donestamp, 'w').close() - dest = os.path.join(dldir, os.path.basename(ud.localpath)) - if not os.path.exists(dest): - os.symlink(ud.localpath, dest) + dest = os.path.join(dldir, os.path.basename(ud.localpath)) + safe_symlink(ud.localpath, dest) + if not os.path.exists(origud.donestamp) or origud.method.need_update(origud, ld): origud.method.download(origud, ld) if hasattr(origud.method,"build_mirror_data"): origud.method.build_mirror_data(origud, ld) return ud.localpath + # Otherwise the result is a local file:// and we symlink to it - if not os.path.exists(origud.localpath): - if os.path.islink(origud.localpath): - # Broken symbolic link - os.unlink(origud.localpath) + safe_symlink(ud.localpath, origud.localpath) - os.symlink(ud.localpath, origud.localpath) update_stamp(origud, ld) return ud.localpath