Skip to content

Commit

Permalink
initdb: make safe_create_dir public
Browse files Browse the repository at this point in the history
Soon we will want to 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.

Signed-off-by: David Turner <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
Signed-off-by: Michael Haggerty <[email protected]>
Signed-off-by: Jeff King <[email protected]>
  • Loading branch information
dturner-tw authored and peff committed Nov 20, 2015
1 parent 7bd9bcf commit eb33876
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
12 changes: 0 additions & 12 deletions builtin/init-db.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ static int init_shared_repository = -1;
static const char *init_db_template_dir;
static const char *git_link;

static 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 void copy_templates_1(struct strbuf *path, struct strbuf *template,
DIR *dir)
{
Expand Down
8 changes: 8 additions & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -1747,4 +1747,12 @@ 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. Only use this for
* directories under $GIT_DIR. Don't use it for working tree
* directories.
*/
void safe_create_dir(const char *dir, int share);

#endif /* CACHE_H */
12 changes: 12 additions & 0 deletions path.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,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;
Expand Down

0 comments on commit eb33876

Please sign in to comment.