git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] lockfile: set lk->fd = -1 in 'rollback_lock_file()'

From
GLGuanqun Lu <guanqun.lu@gmail.com>
Date
Feb 11, 2009, 06:43 UTC
Message-ID
<1234334612-24907-2-git-send-email-guanqun.lu@gmail.com>
In-Reply-To
<1234334612-24907-1-git-send-email-guanqun.lu@gmail.com>
Post-conditions when these functions return successfully:
                    lk->fd == -1?    lk->filename[0] == '\0'?
close_lock_file()       yes                 no
commit_lock_file()      yes                 yes
rollback_lock_file()    no*                 yes

[*] This commit changes this 'no' in rollback_lock_file() to 'yes', which achieves more robust and unified interface.

Signed-off-by: Guanqun Lu <guanqun.lu@gmail.com>
---
 lockfile.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/lockfile.c b/lockfile.c
index 021c337..44e5253 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -243,8 +243,10 @@ int commit_locked_index(struct lock_file *lk)
 void rollback_lock_file(struct lock_file *lk)
 {
 	if (lk->filename[0]) {
-		if (lk->fd >= 0)
+		if (lk->fd >= 0) {
 			close(lk->fd);
+			lk->fd = -1;
+		}
 		unlink(lk->filename);
 	}
 	lk->filename[0] = 0;
-- 
1.6.1.2.392.gb04d1
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 5 in “code cleanup in sha1_file.c: xmalloc -> xcalloc”
  1. 1/2 code cleanup in sha1_file.c: xmalloc -> xcallocGuanqun Lu, Feb 11, 2009
  2. Brandon CaseyFeb 10, 2009
  3. Junio C HamanoFeb 10, 2009
  4. 2/2 lockfile: set lk->fd = -1 in 'rollback_lock_file()'Guanqun Lu, Feb 11, 2009
  5. Junio C HamanoFeb 10, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.