3 #include "reftable-error.h"
4 #include "../lockfile.h"
5 #include "../tempfile.h"
7 int tmpfile_from_pattern(struct reftable_tmpfile
*out
, const char *pattern
)
9 struct tempfile
*tempfile
;
11 tempfile
= mks_tempfile(pattern
);
13 return REFTABLE_IO_ERROR
;
15 out
->path
= tempfile
->filename
.buf
;
16 out
->fd
= tempfile
->fd
;
22 int tmpfile_close(struct reftable_tmpfile
*t
)
24 struct tempfile
*tempfile
= t
->priv
;
25 int ret
= close_tempfile_gently(tempfile
);
28 return REFTABLE_IO_ERROR
;
32 int tmpfile_delete(struct reftable_tmpfile
*t
)
34 struct tempfile
*tempfile
= t
->priv
;
35 int ret
= delete_tempfile(&tempfile
);
36 *t
= REFTABLE_TMPFILE_INIT
;
38 return REFTABLE_IO_ERROR
;
42 int tmpfile_rename(struct reftable_tmpfile
*t
, const char *path
)
44 struct tempfile
*tempfile
= t
->priv
;
45 int ret
= rename_tempfile(&tempfile
, path
);
46 *t
= REFTABLE_TMPFILE_INIT
;
48 return REFTABLE_IO_ERROR
;
52 int flock_acquire(struct reftable_flock
*l
, const char *target_path
,
55 struct lock_file
*lockfile
;
58 lockfile
= reftable_malloc(sizeof(*lockfile
));
60 return REFTABLE_OUT_OF_MEMORY_ERROR
;
62 err
= hold_lock_file_for_update_timeout(lockfile
, target_path
, LOCK_NO_DEREF
,
65 reftable_free(lockfile
);
67 return REFTABLE_LOCK_ERROR
;
71 l
->fd
= get_lock_file_fd(lockfile
);
72 l
->path
= get_lock_file_path(lockfile
);
78 int flock_close(struct reftable_flock
*l
)
80 struct lock_file
*lockfile
= l
->priv
;
84 return REFTABLE_API_ERROR
;
86 ret
= close_lock_file_gently(lockfile
);
89 return REFTABLE_IO_ERROR
;
94 int flock_release(struct reftable_flock
*l
)
96 struct lock_file
*lockfile
= l
->priv
;
102 ret
= rollback_lock_file(lockfile
);
103 reftable_free(lockfile
);
104 *l
= REFTABLE_FLOCK_INIT
;
106 return REFTABLE_IO_ERROR
;
111 int flock_commit(struct reftable_flock
*l
)
113 struct lock_file
*lockfile
= l
->priv
;
117 return REFTABLE_API_ERROR
;
119 ret
= commit_lock_file(lockfile
);
120 reftable_free(lockfile
);
121 *l
= REFTABLE_FLOCK_INIT
;
123 return REFTABLE_IO_ERROR
;