Show 50 quoted lines
> The `odb_transaction_write_pack()` interface for the "files" backend
> relies on git-index-pack(1) to write the specified packfile into an ODB
> transaction as a packfile. To prevent a concurrent housekeeping
> operation from deleting the newly written packfile prior to the
> references being updated, a ".keep" lockfile is also generated by
> git-index-pack(1) via the `--keep` option. Consequently, the ".keep"
> lockfile is written into the ODB transaction alongside the packfile and
> later migrated together to the primary ODB during transaction commit.
>
> In a subsequent commit, writing the lockfile is deferred until
> transaction commit and thus cannot rely on git-index-pack(1) to write
> it. In preparation for this, update `odb_transaction_files_write_pack()`
> to explicitly generate the same ".keep" lockfile itself.
>
> Signed-off-by: Justin Tobler <jltobler@gmail.com>
> ---
> object-file.c | 107 +++++++++++++++++++++++++++++++++++++++-----------
> 1 file changed, 85 insertions(+), 22 deletions(-)
>
> diff --git a/object-file.c b/object-file.c
> index 210984f825..74a31760bc 100644
> --- a/object-file.c
> +++ b/object-file.c
> @@ -1256,6 +1256,47 @@ int read_loose_object(struct repository *repo,
> return ret;
> }
>
> +static int write_pack_lockfile(struct odb_source *source, const char *pack_name,
> + const char *keep_msg)
> +{
> + struct strbuf lock_path = STRBUF_INIT;
> + struct strbuf contents = STRBUF_INIT;
> + int ret;
> + int fd;
> +
> + strbuf_addf(&lock_path, "%s/pack/pack-%s.keep",
> + source->path, pack_name);
> + strbuf_addf(&contents, "%s\n", keep_msg);
> +
> + fd = safe_create_file_with_leading_directories(source->odb->repo,
> + lock_path.buf);
> + if (fd < 0) {
> + ret = error_errno(_("unable to create '%s'"), lock_path.buf);
> + goto out;
> + }
> +
> + if (write_in_full(fd, contents.buf, contents.len) < 0) {
> + ret = error_errno(_("unable to write '%s'"), lock_path.buf);
> + close(fd);
> + unlink(lock_path.buf);