diff options
author | Richard Maw <richard.maw@gmail.com> | 2013-05-23 21:37:05 +0100 |
---|---|---|
committer | Richard Maw <richard.maw@gmail.com> | 2013-05-27 14:38:16 +0100 |
commit | 4b7f212ba3a34d05cc51fccc0c6776d1f3f116c3 (patch) | |
tree | cd3502afd0bddaa46b509461b425e39eeb5d39f8 /lib | |
parent | 630306f6163fed02035b3ef7d65df07e69191910 (diff) | |
download | gitano-4b7f212ba3a34d05cc51fccc0c6776d1f3f116c3.tar.gz |
util: add hardlink_file and copy_symlink functions
hardlink file converts from luxio's raw interface to
boolean success and error message return values, which are used
elsewhere in the codebase.
copy_symlink creates a symlink with the same target as the source
symlink.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitano/util.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/gitano/util.lua b/lib/gitano/util.lua index 2e25f91..44ad5ed 100644 --- a/lib/gitano/util.lua +++ b/lib/gitano/util.lua @@ -229,6 +229,28 @@ local function copy_file(from, to, buffer_size) return true end +-- Adapter function, so hardlink follows the same return convention +-- as the copy_file function +local function hardlink_file(from, to) + local ret, err = luxio.link(from, to) + return ret == 0, luxio.strerror(err) +end + +-- TODO: optionally re-base absolute paths when target is moved +-- outside its base directory +local function copy_symlink(from, to) + local link_target, ret, err + ret, link_target = luxio.readlink(from) + if ret == -1 then + return false, luxio.strerror(link_target) + end + ret, err = luxio.symlink(link_target, to) + if ret ~= 0 then + return false, luxio.strerror(err) + end + return true +end + local function html_escape(s) return (s:gsub("&", "&"): gsub("<", "<"): @@ -372,6 +394,8 @@ return { dirname = dirname, basename = basename, + copy_symlink = copy_symlink, + hardlink_file = hardlink_file, copy_file = copy_file, mkdir_p = mkdir_p, rm_rf = rm_rf, |