Skip to content

Commit c518279

Browse files
committed
Merge branch 'jc/reopen-lock-file'
There are cases where you lock and open to write a file, close it to show the updated contents to external processes, and then have to update the file again while still holding the lock, but the lockfile API lacked support for such an access pattern. * jc/reopen-lock-file: lockfile: allow reopening a closed but still locked file
2 parents 96db324 + 93dcaea commit c518279

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ extern NORETURN void unable_to_lock_index_die(const char *path, int err);
585585
extern int hold_lock_file_for_update(struct lock_file *, const char *path, int);
586586
extern int hold_lock_file_for_append(struct lock_file *, const char *path, int);
587587
extern int commit_lock_file(struct lock_file *);
588+
extern int reopen_lock_file(struct lock_file *);
588589
extern void update_index_if_able(struct index_state *, struct lock_file *);
589590

590591
extern int hold_locked_index(struct lock_file *, int);

lockfile.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,16 @@ int close_lock_file(struct lock_file *lk)
237237
return close(fd);
238238
}
239239

240+
int reopen_lock_file(struct lock_file *lk)
241+
{
242+
if (0 <= lk->fd)
243+
die(_("BUG: reopen a lockfile that is still open"));
244+
if (!lk->filename[0])
245+
die(_("BUG: reopen a lockfile that has been committed"));
246+
lk->fd = open(lk->filename, O_WRONLY);
247+
return lk->fd;
248+
}
249+
240250
int commit_lock_file(struct lock_file *lk)
241251
{
242252
char result_file[PATH_MAX];

0 commit comments

Comments
 (0)