@matheusbsbs / matheus-bagliano / commits / e24317b4d0
Fork 0

Test in git-init-db if the filemode can be trusted

... and if not, write an appropriate .git/config. Of course, that happens only if no config file was yet created (by a template or a hook). Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>

Johannes Schindelin committed Oct 26, 2005 at 01:43 UTC e24317b4d093e4b148996172d0b749f09a0e6f2e
1 file changed +37
init-db.c
+37
@@ -196,6 +196,43 @@ static void create_default_files(const char *git_dir,
196 }
197 path[len] = 0;
198 copy_templates(path, len, template_path);
199 +
200 + /*
201 + * Find out if we can trust the executable bit.
202 + */
203 + safe_create_dir(path);
204 + strcpy(path + len, "config");
205 + if (access(path, R_OK) < 0) {
206 + static const char contents[] =
207 + "#\n"
208 + "# This is the config file\n"
209 + "#\n"
210 + "\n"
211 + "; core variables\n"
212 + "[core]\n"
213 + " ; Don't trust file modes\n"
214 + " filemode = false\n"
215 + "\n";
216 + FILE *config = fopen(path, "w");
217 + struct stat st;
218 +
219 + if (!config)
220 + die("Can not write to %s?", path);
221 +
222 + fwrite(contents, sizeof(contents)-1, 1, config);
223 +
224 + fclose(config);
225 +
226 + if (!lstat(path, &st)) {
227 + struct stat st2;
228 + if (!chmod(path, st.st_mode ^ S_IXUSR) &&
229 + !lstat(path, &st2) &&
230 + st.st_mode != st2.st_mode)
231 + unlink(path);
232 + else
233 + fprintf(stderr, "Ignoring file modes\n");
234 + }
235 + }
236 }
237
238 static const char init_db_usage[] =