summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@gmail.com>2013-05-23 21:37:05 +0100
committerRichard Maw <richard.maw@gmail.com>2013-05-27 14:38:16 +0100
commit4b7f212ba3a34d05cc51fccc0c6776d1f3f116c3 (patch)
treecd3502afd0bddaa46b509461b425e39eeb5d39f8
parent630306f6163fed02035b3ef7d65df07e69191910 (diff)
downloadgitano-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.
-rw-r--r--lib/gitano/util.lua24
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("&", "&amp;"):
gsub("<", "&lt;"):
@@ -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,