Re: [PATCH v4 23/26] initdb: move safe_create_dir into common code

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

 



David Turner <dturner@xxxxxxxxxxxxxxxx> writes:

> In a moment, we'll create initdb functions for ref backends, and code
> from initdb that calls this function needs to move into the files
> backend.  So this function needs to be public.

OK, but unlike the static function, being in public interface part
can invite mistakes of using this for things outside $GIT_DIR [*1*].
Let's have "Never use this for working tree directories" somewhere
in its docstring.

Other than that, this one, 24/26 and 25/26 looked fine to me.

Thanks.

[Footnote]

*1* Anything created by this function and everything underneath are
repository metadata and this function must not be used to do with
anything with the working tree, as it is clear with the use of
adjust_shared_perm().

> diff --git a/cache.h b/cache.h
> index 9a905a8..1d8a051 100644
> --- a/cache.h
> +++ b/cache.h
> @@ -1737,4 +1737,9 @@ void stat_validity_update(struct stat_validity *sv, int fd);
>  int versioncmp(const char *s1, const char *s2);
>  void sleep_millisec(int millisec);
>  
> +/*
> + * Create a directory and (if share is nonzero) adjust its permissions
> + * according to the shared_repository setting.
> + */
> +void safe_create_dir(const char *dir, int share);
>  #endif /* CACHE_H */
> diff --git a/path.c b/path.c
> index 212695a..9e0283c 100644
> --- a/path.c
> +++ b/path.c
> @@ -723,6 +723,18 @@ int adjust_shared_perm(const char *path)
>  	return 0;
>  }
>  
> +void safe_create_dir(const char *dir, int share)
> +{
> +	if (mkdir(dir, 0777) < 0) {
> +		if (errno != EEXIST) {
> +			perror(dir);
> +			exit(1);
> +		}
> +	}
> +	else if (share && adjust_shared_perm(dir))
> +		die(_("Could not make %s writable by group"), dir);
> +}
> +
>  static int have_same_root(const char *path1, const char *path2)
>  {
>  	int is_abs1, is_abs2;
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[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