summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2011-06-08 04:16:47 -0700
committerVicent Martí <tanoku@gmail.com>2011-06-08 04:16:47 -0700
commit1071c56519866afd41db2f30705eba8406b6a4a1 (patch)
treed306b0447ecb30ecf51c89182f2cfbac37f00cc4
parent3a12891f53cd5c349c0eed2ace7a9a900432aa5e (diff)
parentbb9272dd7af68590452cbf91b0b8583e22f0c066 (diff)
downloadlibgit2-1071c56519866afd41db2f30705eba8406b6a4a1.tar.gz
Merge pull request #246 from carlosmn/keep-lock
Keep the lockfile if we fail to lock it
-rw-r--r--src/filebuf.c2
-rw-r--r--tests/t00-core.c12
2 files changed, 13 insertions, 1 deletions
diff --git a/src/filebuf.c b/src/filebuf.c
index d0579b16b..ca13e6181 100644
--- a/src/filebuf.c
+++ b/src/filebuf.c
@@ -75,7 +75,7 @@ void git_filebuf_cleanup(git_filebuf *file)
if (file->fd >= 0)
gitfo_close(file->fd);
- if (file->path_lock && gitfo_exists(file->path_lock) == GIT_SUCCESS)
+ if (file->fd >= 0 && file->path_lock && gitfo_exists(file->path_lock) == GIT_SUCCESS)
gitfo_unlink(file->path_lock);
if (file->digest)
diff --git a/tests/t00-core.c b/tests/t00-core.c
index 9498178cf..5cd4025d3 100644
--- a/tests/t00-core.c
+++ b/tests/t00-core.c
@@ -26,6 +26,7 @@
#include "vector.h"
#include "fileops.h"
+#include "filebuf.h"
BEGIN_TEST(string0, "compare prefixes")
must_be_true(git__prefixcmp("", "") == 0);
@@ -661,6 +662,15 @@ BEGIN_TEST(dirent4, "make sure that strange looking filenames ('..c') are traver
must_pass(knockdown(&odd));
END_TEST
+BEGIN_TEST(filebuf0, "make sure git_filebuf_open doesn't delete an existing lock")
+ git_filebuf file;
+ char test[] = "test", testlock[] = "test.lock";
+
+ must_pass(gitfo_creat(testlock, 0744));
+ must_fail(git_filebuf_open(&file, test, 0));
+ must_pass(gitfo_exists(testlock));
+ must_pass(gitfo_unlink(testlock));
+END_TEST
BEGIN_SUITE(core)
ADD_TEST(string0);
@@ -683,4 +693,6 @@ BEGIN_SUITE(core)
ADD_TEST(dirent2);
ADD_TEST(dirent3);
ADD_TEST(dirent4);
+
+ ADD_TEST(filebuf0);
END_SUITE