Thread (41 messages) 41 messages, 2 authors, 2016-06-15

[PATCH v7 03/38] close_lock_file(): exit (successfully) if file is already closed

flat view
DORMANTno replies

From: Michael Haggerty <hidden>
Date: 2016-06-15 23:02:37
Subsystem: the rest · Maintainer: Linus Torvalds

Revision v7 of 6 in this series.

Revisions (6)
  1. v2 [diff vs current]
  2. v3 [diff vs current]
  3. v4 [diff vs current]
  4. v5 [diff vs current]
  5. v6 [diff vs current]
  6. v7 current
Suggested-by: Jonathan Nieder <redacted>
Signed-off-by: Michael Haggerty <redacted>
---
 lockfile.c   | 6 +++++-
 read-cache.c | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/lockfile.c b/lockfile.c
index f1ce154..d02c3bf 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -233,6 +233,10 @@ int hold_lock_file_for_append(struct lock_file *lk, const char *path, int flags)
 int close_lock_file(struct lock_file *lk)
 {
 	int fd = lk->fd;
+
+	if (fd < 0)
+		return 0;
+
 	lk->fd = -1;
 	return close(fd);
 }
@@ -251,7 +255,7 @@ int commit_lock_file(struct lock_file *lk)
 {
 	char result_file[PATH_MAX];
 	size_t i;
-	if (lk->fd >= 0 && close_lock_file(lk))
+	if (close_lock_file(lk))
 		return -1;
 	strcpy(result_file, lk->filename);
 	i = strlen(result_file) - 5; /* .lock */
diff --git a/read-cache.c b/read-cache.c
index 2fc1182..5ffb1d7 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2042,7 +2042,7 @@ void set_alternate_index_output(const char *name)
 static int commit_locked_index(struct lock_file *lk)
 {
 	if (alternate_index_output) {
-		if (lk->fd >= 0 && close_lock_file(lk))
+		if (close_lock_file(lk))
 			return -1;
 		if (rename(lk->filename, alternate_index_output))
 			return -1;
-- 
2.1.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help