diff options
| author | Romain Geissler <romain.geissler@gmail.com> | 2011-06-03 21:18:24 +0200 |
|---|---|---|
| committer | Romain Geissler <romain.geissler@gmail.com> | 2011-06-03 23:08:42 +0200 |
| commit | 1549cba9a4f7d9ad79441b748937bbe606ba79c1 (patch) | |
| tree | 6fd6a4d881062713122f0cdf5e6fff58d4086f21 /src/fileops.c | |
| parent | bc6484912ebb3db2ac9637abebdeadd28f6d84c3 (diff) | |
| download | libgit2-1549cba9a4f7d9ad79441b748937bbe606ba79c1.tar.gz | |
Filebuf: Fixed a TODO in filebuf (real lock in lock_file)
Added gitfo_creat_locked and gitfo_creat_locked_force
Diffstat (limited to 'src/fileops.c')
| -rw-r--r-- | src/fileops.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/fileops.c b/src/fileops.c index 11634c263..c407515f1 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -66,6 +66,20 @@ int gitfo_creat_force(const char *path, int mode) return gitfo_creat(path, mode); } +int gitfo_creat_locked(const char *path, int mode) +{ + int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_EXCL, mode); + return fd >= 0 ? fd : git__throw(GIT_EOSERR, "Failed to create locked file. Could not open %s", path); +} + +int gitfo_creat_locked_force(const char *path, int mode) +{ + if (gitfo_mkdir_2file(path) < GIT_SUCCESS) + return git__throw(GIT_EOSERR, "Failed to create locked file %s", path); + + return gitfo_creat_locked(path, mode); +} + int gitfo_read(git_file fd, void *buf, size_t cnt) { char *b = buf; |
