--- 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
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.
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
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
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
-- @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
-- @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
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
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
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