Re: [PATCH v4 10/12] refs: implement removal of ref storages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Patrick Steinhardt <ps@xxxxxx> writes:

[snip]

> diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
> index bffed9257f..e555be4671 100644
> --- a/refs/reftable-backend.c
> +++ b/refs/reftable-backend.c
> @@ -1,6 +1,7 @@
>  #include "../git-compat-util.h"
>  #include "../abspath.h"
>  #include "../chdir-notify.h"
> +#include "../dir.h"
>  #include "../environment.h"
>  #include "../gettext.h"
>  #include "../hash.h"
> @@ -343,6 +344,56 @@ static int reftable_be_create_on_disk(struct ref_store *ref_store,
>  	return 0;
>  }
>
> +static int reftable_be_remove_on_disk(struct ref_store *ref_store,
> +				      struct strbuf *err)
> +{
> +	struct reftable_ref_store *refs =
> +		reftable_be_downcast(ref_store, REF_STORE_WRITE, "remove");
> +	struct strbuf sb = STRBUF_INIT;
> +	int ret = 0;
> +
> +	/*
> +	 * Release the ref store such that all stacks are closed. This is
> +	 * required so that the "tables.list" file is not open anymore, which
> +	 * would otherwise make it impossible to remove the file on Windows.
> +	 */
> +	reftable_be_release(ref_store);
> +
> +	strbuf_addf(&sb, "%s/reftable", refs->base.gitdir);
> +	if (remove_dir_recursively(&sb, 0) < 0) {
> +		strbuf_addf(err, "could not delete reftables: %s",
> +			    strerror(errno));
> +		ret = -1;
> +	}
> +	strbuf_reset(&sb);
> +
> +	strbuf_addf(&sb, "%s/HEAD", refs->base.gitdir);
> +	if (unlink(sb.buf) < 0) {
> +		strbuf_addf(err, "could not delete stub HEAD: %s",
> +			    strerror(errno));
> +		ret = -1;
> +	}
> +	strbuf_reset(&sb);
> +
> +	strbuf_addf(&sb, "%s/refs/heads", refs->base.gitdir);
> +	if (unlink(sb.buf) < 0) {
> +		strbuf_addf(err, "could not delete stub heads: %s",
> +			    strerror(errno));
> +		ret = -1;
> +	}
> +	strbuf_reset(&sb);
> +
> +	strbuf_addf(&sb, "%s/refs", refs->base.gitdir);
> +	if (rmdir(sb.buf) < 0) {
> +		strbuf_addf(err, "could not delete stub heads: %s",

Nit: Wouldn't it be nicer to be able to differentiate this from the
previous case? Both have the same error message.

Otherwise this patch looks good, since we use unlink(2), that handles
symrefs which are symbolic links too.

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux