diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2014-08-24 11:45:20 -0700 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2014-08-24 11:48:41 -0700 |
commit | 13accf4d0633b33c5cfe340253dce6956191e789 (patch) | |
tree | b8b139fd314e2a81b96bcab8c83859a68cecf2a6 | |
parent | a24d48b9f7daa343825e2168c46282a8f96ac007 (diff) | |
download | gitano-13accf4d0633b33c5cfe340253dce6956191e789.tar.bz2 |
Clean up copy routines a little to improve repository copy functionality
-rw-r--r-- | lib/gitano/util.lua | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/lib/gitano/util.lua b/lib/gitano/util.lua index ab8730a..a07b410 100644 --- a/lib/gitano/util.lua +++ b/lib/gitano/util.lua @@ -248,18 +248,24 @@ local function copy_file(from, to, buffer_size) repeat local ok local bytes, emsg = fromfile:read(buffer_size) - if not bytes then + if (not bytes) and emsg then fromfile:close() tofile:close() return false, emsg end - ok, write_count, emsg = _write_all(tofile, bytes) - if not ok then - fromfile:close() - tofile:close() - return false, emsg + if bytes then + ok, write_count, emsg = _write_all(tofile, bytes) + if not ok then + fromfile:close() + tofile:close() + return false, emsg + end + else + write_count = 0 end until write_count == 0 + fromfile:close() + tofile:close() return true end @@ -293,6 +299,23 @@ 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 @@ -311,9 +334,12 @@ local function copy_dir(from, to, copy_cbs, filter_cb) return ret, err end for filename, fileinfo in dirp:iterate() do - local copycb = copy_cbs[fileinfo.d_type] local filefrom = path_join(from, filename) local fileto = path_join(to, filename) + local copycb, err = gen_cb(copy_cbs, fileinfo.d_type, filefrom) + if not copycb then + return false, err + end if filter_cb(from, filename, fileinfo) then log.ddebug("Skipping file", filename) elseif fileinfo.d_type == luxio.DT_REG then |