summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2016-09-24 15:13:36 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2016-09-24 15:14:58 +0100
commit197fd7fada08f053b9c6e1d13f3d7c137f00116d (patch)
tree713eec5aac3c827fb803be2b38c63f31162bd2fa /lib
parentcd7321e746030630d2434254e70461e53586f771 (diff)
downloadgitano-197fd7fada08f053b9c6e1d13f3d7c137f00116d.tar.gz
UTIL: Add temporary file support
Diffstat (limited to 'lib')
-rw-r--r--lib/gitano/util.lua17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/gitano/util.lua b/lib/gitano/util.lua
index dd40eb3..2e80d68 100644
--- a/lib/gitano/util.lua
+++ b/lib/gitano/util.lua
@@ -517,6 +517,22 @@ local function add_splitable(context, key, value, splitter,
end
end
+local tempfilecounter = 0
+local function tempfile(repo)
+ local repopath = repo:fs_path()
+ local temppattern = path_join(
+ repopath, ("gitanotmp.%d.%d.XXXXXX"):format(tempfilecounter,
+ luxio.getpid()))
+ tempfilecounter = tempfilecounter + 1
+ if luxio.mkstemp then
+ return luxio.mkstemp(temppattern)
+ end
+ -- No mkstemp so let's hope that the %d.%d is enough...
+ local fd = luxio.open(temppattern, luxio.O_RDWR + luxio.O_CREAT,
+ tonumber("700", 8))
+ return fd, temppattern
+end
+
return {
parse_cmdline = _parse_cmdline,
@@ -526,6 +542,7 @@ return {
path_join = path_join,
dirname = dirname,
basename = basename,
+ tempfile = tempfile,
copy_symlink = copy_symlink,
hardlink_file = hardlink_file,