diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2016-01-05 15:33:16 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2016-01-05 15:35:23 +0000 |
commit | 922cd6f69e3c765d1a2c341313dedb1e4a153ede (patch) | |
tree | ffe5fe9a34ce54185c75c91bebf48eb44a7cf5c5 | |
parent | 264e80751592d3c8b3aa4cf09bd71660f745f994 (diff) | |
download | gitano-922cd6f69e3c765d1a2c341313dedb1e4a153ede.tar.bz2 |
util.copy_dir: Make more tolerant to DT_UNKNOWN
-rw-r--r-- | lib/gitano/util.lua | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/lib/gitano/util.lua b/lib/gitano/util.lua index a07b410..dd40eb3 100644 --- a/lib/gitano/util.lua +++ b/lib/gitano/util.lua @@ -299,23 +299,6 @@ end local _exclude_builtin = { ["."] = true, [".."] = true } local copy_dir_filter_base = copy_pathname_filter(_exclude_builtin) -local function gen_cb(cbs, ftype, fname) - if ftype == luxio.DT_UNKNOWN then - local statdata, err = sio.lstat(fname) - if not statdata then - return nil, err - end - if luxio.S_ISDIR(statdata.mode) ~= 0 then - ftype = luxio.DT_DIR - elseif luxio.S_ISLNK(statdata.mode) ~= 0 then - ftype = luxio.DT_LNK - elseif luxio.S_ISREG(statdata.mode) ~= 0 then - ftype = luxio.DT_REG - end - end - return cbs[ftype], "No callback provided" -end - local copy_dir_copy_callbacks -- filter_cb is a function, which takes (parent_path, filename, fileinfo) -- and returns true if the component should not be copied @@ -335,10 +318,27 @@ local function copy_dir(from, to, copy_cbs, filter_cb) end for filename, fileinfo in dirp:iterate() do local filefrom = path_join(from, filename) + if fileinfo.d_type == luxio.DT_UNKNOWN then + -- Stat and translate mode to type if type unknown + local stat, err = sio.lstat(filefrom) + if not stat then + log.critical("Stat file", filefrom, "failed:", err) + return false, err + end + fileinfo.d_type = ({ + [luxio.S_IFBLK] = luxio.DT_BLK, + [luxio.S_IFCHR] = luxio.DT_CHR, + [luxio.S_IFDIR] = luxio.DT_DIR, + [luxio.S_IFIFO] = luxio.DT_FIFO, + [luxio.S_IFLNK] = luxio.DT_LNK, + [luxio.S_IFREG] = luxio.DT_REG, + [luxio.S_IFSOCK] = luxio.DT_SOCK, + })[luxio.bit.band(stat.mode, luxio.S_IFMT)] + end local fileto = path_join(to, filename) - local copycb, err = gen_cb(copy_cbs, fileinfo.d_type, filefrom) + local copycb = copy_cbs[fileinfo.d_type] if not copycb then - return false, err + return false, "No callback provided" end if filter_cb(from, filename, fileinfo) then log.ddebug("Skipping file", filename) |