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 <dturner@twopensource.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Jeff King <peff@peff.net>
David Turner committed
Nov 10, 2015 at 12:42 UTC
eb33876c262bec79a127b82a3a853ad00665d894
3 files changed
+20
-12
builtin/init-db.c
-12
@@ -24,18 +24,6 @@ static int init_shared_repository = -1;
24
static const char *init_db_template_dir;
25
static const char *git_link;
26
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
-
27
static void copy_templates_1(struct strbuf *path, struct strbuf *template,
28
DIR *dir)
29
{
cache.h
+8
@@ -1747,4 +1747,12 @@ void stat_validity_update(struct stat_validity *sv, int fd);
1747
int versioncmp(const char *s1, const char *s2);
1748
void sleep_millisec(int millisec);
1749
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
+
1758
#endif /* CACHE_H */
path.c
+12
@@ -740,6 +740,18 @@ int adjust_shared_perm(const char *path)
740
return 0;
741
}
742
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
+
755
static int have_same_root(const char *path1, const char *path2)
756
{
757
int is_abs1, is_abs2;