From e54344c35219b8a793d84902c0b06e51fb8d74b9 Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Tue, 7 May 2019 18:49:16 +0200 Subject: [PATCH] e2build: do not re-create last link pointing to the same dir Signed-off-by: Tobias Ulmer --- local/e2build.lua | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/local/e2build.lua b/local/e2build.lua index 307ac58..d85aabc 100644 --- a/local/e2build.lua +++ b/local/e2build.lua @@ -1159,6 +1159,8 @@ function e2build.build_process_class:_linklast(res, rbs) return true else -- otherwise create a symlink + local createsymlink = true + dst, re = cache.fetch_file_path(cache.cache(), server, location) if not dst then return false, e:cat(re) @@ -1166,19 +1168,49 @@ function e2build.build_process_class:_linklast(res, rbs) dst = e2lib.dirname(dst) -- we only care about the directory - -- create the last link + -- create directory to 'last' if it doesn't already exist rc, re = e2lib.mkdir_recursive(e2lib.dirname(lnk)) if not rc then return false, e:cat(re) end - if e2lib.lstat(lnk) then - e2lib.unlink_recursive(lnk) -- ignore errors, symlink will catch it + -- last symlink or directory (or file) exists? + rc, re = e2lib.lstat(lnk) + if rc then + if rc.type == 'directory' then + rc, re = e2lib.unlink_recursive(lnk) + if not rc then + return false, e:cat(re) + end + else + local st_tgt, st_dst + + st_dst, re = e2lib.lstat(dst) + if not st_dst then + return false, e:cat(re) + end + + -- Follow link to target. + st_tgt, re = e2lib.stat(lnk) + if st_tgt and + st_tgt.dev == st_dst.dev and st_tgt.ino == st_dst.ino then + createsymlink = false + else + -- If target of the link doesn't exists, delete the link. + -- If target and dst are not identical, delete the link. + rc, re = e2lib.unlink(lnk) + if not rc then + return false, e:cat(re) + end + end + end end - rc, re = e2lib.symlink(dst, lnk) - if not rc then - return false, e:cat(re) + if createsymlink then + rc, re = e2lib.symlink(dst, lnk) + if not rc then + return false, e:cat(re) + end end end -- 2.39.5