summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@gmail.com>2013-05-23 21:53:55 +0100
committerRichard Maw <richard.maw@gmail.com>2013-05-27 14:38:17 +0100
commitc8a485d91f8378a49146d2d53cfbb760fbd23be3 (patch)
treef7bb2deffbd9945d4ca16fd43bdc1b7694ff780d
parentd726b2b35c633a82428055a3d1081a4eafd02a7a (diff)
downloadgitano-c8a485d91f8378a49146d2d53cfbb760fbd23be3.tar.gz
repository: don't break a copy in progress
This attempts to create the target repository outside the call to util.copy_dir(), since internally it uses mkdir_p, which doesn't distinguish between a repository that already exists. If this check is not made, then it will fail to create a file inside the repository since it already exists, then attempt to clean up after itself, possibly silently breaking the in progress copy.
-rw-r--r--lib/gitano/repository.lua10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/gitano/repository.lua b/lib/gitano/repository.lua
index 36f9579..9667073 100644
--- a/lib/gitano/repository.lua
+++ b/lib/gitano/repository.lua
@@ -522,6 +522,16 @@ function repo_method:copy_to(target)
return false, "Cannot prepare path leading to repository."
end
+ -- attempt to create the target directory, so we can detect
+ -- a copy is already in progress and return without removing
+ -- the target directory
+ ok, err = luxio.mkdir(temp_path, sio.tomode'0755')
+ if ok ~= 0 then
+ log.error("Failed to copy repository", self:fs_path(),
+ "to", newpath .. ":", "Copy already in progress")
+ return false, "Copy already in progress"
+ end
+
local from = self:fs_path()
local function filter(parent, name, info)
return parent == from and name == "objects"