Skip to content

Commit

Permalink
Merge branch 'jc/reopen-lock-file'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Junio C Hamano committed Sep 2, 2014
2 parents 96db324 + 93dcaea commit c518279
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ extern NORETURN void unable_to_lock_index_die(const char *path, int err);
extern int hold_lock_file_for_update(struct lock_file *, const char *path, int);
extern int hold_lock_file_for_append(struct lock_file *, const char *path, int);
extern int commit_lock_file(struct lock_file *);
extern int reopen_lock_file(struct lock_file *);
extern void update_index_if_able(struct index_state *, struct lock_file *);

extern int hold_locked_index(struct lock_file *, int);
Expand Down
10 changes: 10 additions & 0 deletions lockfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,16 @@ int close_lock_file(struct lock_file *lk)
return close(fd);
}

int reopen_lock_file(struct lock_file *lk)
{
if (0 <= lk->fd)
die(_("BUG: reopen a lockfile that is still open"));
if (!lk->filename[0])
die(_("BUG: reopen a lockfile that has been committed"));
lk->fd = open(lk->filename, O_WRONLY);
return lk->fd;
}

int commit_lock_file(struct lock_file *lk)
{
char result_file[PATH_MAX];
Expand Down

0 comments on commit c518279

Please sign in to comment.