]> git.e2factory.org Git - e2factory.git/commitdiff
e2lib: split up stat() into lstat() and remove inconsistencies
authorTobias Ulmer <tu@emlix.com>
Tue, 11 Oct 2016 16:08:33 +0000 (18:08 +0200)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:41:18 +0000 (15:41 +0100)
This allows symlinks (not encouraged!) to work more consistently.

It also fixes a bug where we cached the symlink information instead of
the real file.

Prior to this change stat(foo, true) worked like posix stat(), while
stat(foo) or stat(foo, false) worked like lstat. This change undoes the
confusion, both functions work like their posix namesakes.

Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/e2lib.lua
local/e2build.lua
local/result.lua
local/source.lua
plugins/files.lua

index 2df095d7df9b9da988e8d2e5c6688c4664a97bf4..2987808f02459f1638e2cfa6119b246d2d3268df 100644 (file)
@@ -162,13 +162,12 @@ end
 
 --- Get file status information.
 -- @param path Path to the file, including special files.
--- @param followlinks Whether symlinks should be followed, or information
---        about the link should be returned (boolean).
 -- @return Dirent table containing attributes (see @{dirent}), or false on error
 -- @return Error object on failure.
-function e2lib.stat(path, followlinks)
-    local dirent, errstring = le2lib.stat(path, followlinks)
+function e2lib.stat(path)
+    local dirent, errstring
 
+    dirent, errstring = le2lib.stat(path, true)
     if not dirent then
         return false, err.new("stat failed: %s: %s", path, errstring)
     end
@@ -176,6 +175,21 @@ function e2lib.stat(path, followlinks)
     return dirent
 end
 
+--- Get file status information, don't follow symbolic links.
+-- @param path Path to the file, including special files.
+-- @return Dirent table containing attributes (see @{dirent}), or false on error
+-- @return Error object on failure.
+function e2lib.lstat(path)
+    local dirent, errstring
+
+    dirent, errstring = le2lib.stat(path, false)
+    if not dirent then
+        return false, err.new("lstat failed: %s: %s", path, errstring)
+    end
+
+    return dirent
+end
+
 --- Checks if file exists.
 -- If executable is true, it also checks whether the file is executable.
 -- @param path Path to check.
@@ -613,7 +627,7 @@ function e2lib.rotate_log(file)
     local files = {}
     local dst
 
-    if not e2lib.stat(file) then
+    if not e2lib.lstat(file) then -- file may be an invalid symlink
         return true
     end
 
@@ -1850,7 +1864,7 @@ function e2lib.unlink_recursive(pathname)
     local de, rc, re
     local filepath
 
-    de, re = e2lib.stat(pathname, false) -- do not follow links
+    de, re = e2lib.lstat(pathname) -- do not follow links
     if not de then
         return false, re
     end
@@ -1863,7 +1877,7 @@ function e2lib.unlink_recursive(pathname)
 
             filepath = e2lib.join(pathname, file)
 
-            de, re = e2lib.stat(filepath, false) -- do not follow links
+            de, re = e2lib.lstat(filepath) -- do not follow links
             if not de then
                 return false, re
             end
@@ -2232,7 +2246,7 @@ end
 -- @param dir string: path
 -- @return bool
 function e2lib.isdir(dir)
-    local t = e2lib.stat(dir, true)
+    local t = e2lib.stat(dir)
     if t and t.type == "directory" then
         return true
     end
@@ -2244,7 +2258,7 @@ end
 -- @param dir string: path
 -- @return bool
 function e2lib.isfile(path)
-    local t = e2lib.stat(path, true)
+    local t = e2lib.stat(path)
     if t and t.type == "regular" then
         return true
     end
index f9d62a3df215371b8f9721a0beb2592ac16e2bef..b739c6e37cd29699a7906f8ae9f0db1f1b0988ab 100644 (file)
@@ -379,7 +379,7 @@ function e2build.build_process_class:helper_chroot_remove(res)
         return false, e:cat(re)
     end
     local f = e2lib.join(info.root, "playground")
-    local s = e2lib.stat(f)
+    local s = e2lib.lstat(f)
     if s and s.type == "symbolic-link" then
         rc, re = e2lib.unlink(f)
         if not rc then
@@ -1056,7 +1056,7 @@ function e2build.build_process_class:_linklast(res, return_flags)
         e2lib.logf(3, "%s: copy to out/%s/last, server %q has no cache/not local",
             res:get_name(), res:get_name(), server)
 
-        if e2lib.stat(lnk, false) then
+        if e2lib.lstat(lnk) then
             e2lib.unlink_recursive(lnk) -- ignore errors
         end
 
@@ -1085,7 +1085,7 @@ function e2build.build_process_class:_linklast(res, return_flags)
             return false, e:cat(re)
         end
 
-        if e2lib.stat(lnk, false) then
+        if e2lib.lstat(lnk) then
             e2lib.unlink_recursive(lnk) -- ignore errors, symlink will catch it
         end
 
index 27df5cfffaf6fb2496da328c052d760002407be3..e4a7c66cedba1600b0f1df76bbcb0d206d9f32c0 100644 (file)
@@ -589,7 +589,7 @@ local function gather_result_paths(info, basedir, results)
 
         resdir = e2tool.resultdir(entry, info.root)
         resconfig = e2tool.resultconfig(entry, info.root)
-        s = e2lib.stat(resdir, false)
+        s = e2lib.stat(resdir)
         if s.type == "directory" then
             if e2lib.exists(resconfig) then
                 table.insert(results, entry)
index fbe70a62506441f0f693de115027fbb48dc69068..d6572adc4b06d67df411fdc7cbfbc98eb7a4451b 100644 (file)
@@ -147,7 +147,7 @@ local function gather_source_paths(info, basedir, sources)
 
         sdir = e2tool.sourcedir(entry, info.root)
         sconfig = e2tool.sourceconfig(entry, info.root)
-        s = e2lib.stat(sdir, false)
+        s = e2lib.stat(sdir)
         if s.type == "directory" then
             if e2lib.exists(sconfig) then
                 table.insert(sources, entry)
index cf4aca4ad947059da5191add649a5ff488e09db7..39f3a3d51876ad92181c44d6151a360660d93f69 100644 (file)
@@ -566,7 +566,7 @@ function files.prepare_source(info, sourcename, sourceset, buildpath)
             end
 
             local expected_location = e2lib.join(buildpath, file.unpack)
-            if not e2lib.stat(expected_location, true) then
+            if not e2lib.stat(expected_location) then
                 return false, err.new("expected unpack location '%s' does not exist",
                     expected_location)
             end