Skip to content

Commit eb33876

Browse files
dturner-twpeff
authored andcommitted
initdb: make safe_create_dir public
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]>
1 parent 7bd9bcf commit eb33876

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

builtin/init-db.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,6 @@ static int init_shared_repository = -1;
2424
static const char *init_db_template_dir;
2525
static const char *git_link;
2626

27-
static void safe_create_dir(const char *dir, int share)
28-
{
29-
if (mkdir(dir, 0777) < 0) {
30-
if (errno != EEXIST) {
31-
perror(dir);
32-
exit(1);
33-
}
34-
}
35-
else if (share && adjust_shared_perm(dir))
36-
die(_("Could not make %s writable by group"), dir);
37-
}
38-
3927
static void copy_templates_1(struct strbuf *path, struct strbuf *template,
4028
DIR *dir)
4129
{

cache.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,4 +1747,12 @@ void stat_validity_update(struct stat_validity *sv, int fd);
17471747
int versioncmp(const char *s1, const char *s2);
17481748
void sleep_millisec(int millisec);
17491749

1750+
/*
1751+
* Create a directory and (if share is nonzero) adjust its permissions
1752+
* according to the shared_repository setting. Only use this for
1753+
* directories under $GIT_DIR. Don't use it for working tree
1754+
* directories.
1755+
*/
1756+
void safe_create_dir(const char *dir, int share);
1757+
17501758
#endif /* CACHE_H */

path.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,18 @@ int adjust_shared_perm(const char *path)
740740
return 0;
741741
}
742742

743+
void safe_create_dir(const char *dir, int share)
744+
{
745+
if (mkdir(dir, 0777) < 0) {
746+
if (errno != EEXIST) {
747+
perror(dir);
748+
exit(1);
749+
}
750+
}
751+
else if (share && adjust_shared_perm(dir))
752+
die(_("Could not make %s writable by group"), dir);
753+
}
754+
743755
static int have_same_root(const char *path1, const char *path2)
744756
{
745757
int is_abs1, is_abs2;

0 commit comments

Comments
 (0)