summaryrefslogtreecommitdiff
path: root/builtin-init-db.c
diff options
context:
space:
mode:
authorThomas Rast <trast@student.ethz.ch>2009-06-27 15:58:47 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-06-27 18:14:53 (GMT)
commit0721c314a5c8fddc877140ab5a333c42c62f780d (patch)
tree3fbea50f91636df092ac245284e811a32738842c /builtin-init-db.c
parentd824cbba02a4061400a0e382f9bd241fbbff34f0 (diff)
downloadgit-0721c314a5c8fddc877140ab5a333c42c62f780d.zip
git-0721c314a5c8fddc877140ab5a333c42c62f780d.tar.gz
git-0721c314a5c8fddc877140ab5a333c42c62f780d.tar.bz2
Use die_errno() instead of die() when checking syscalls
Lots of die() calls did not actually report the kind of error, which can leave the user confused as to the real problem. Use die_errno() where we check a system/library call that sets errno on failure, or one of the following that wrap such calls: Function Passes on error from -------- -------------------- odb_pack_keep open read_ancestry fopen read_in_full xread strbuf_read xread strbuf_read_file open or strbuf_read_file strbuf_readlink readlink write_in_full xwrite Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-init-db.c')
-rw-r--r--builtin-init-db.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/builtin-init-db.c b/builtin-init-db.c
index d1fa12a..4a56006 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -61,20 +61,20 @@ static void copy_templates_1(char *path, int baselen,
memcpy(template + template_baselen, de->d_name, namelen+1);
if (lstat(path, &st_git)) {
if (errno != ENOENT)
- die("cannot stat %s", path);
+ die_errno("cannot stat '%s'", path);
}
else
exists = 1;
if (lstat(template, &st_template))
- die("cannot stat template %s", template);
+ die_errno("cannot stat template '%s'", template);
if (S_ISDIR(st_template.st_mode)) {
DIR *subdir = opendir(template);
int baselen_sub = baselen + namelen;
int template_baselen_sub = template_baselen + namelen;
if (!subdir)
- die("cannot opendir %s", template);
+ die_errno("cannot opendir '%s'", template);
path[baselen_sub++] =
template[template_baselen_sub++] = '/';
path[baselen_sub] =
@@ -91,16 +91,17 @@ static void copy_templates_1(char *path, int baselen,
int len;
len = readlink(template, lnk, sizeof(lnk));
if (len < 0)
- die("cannot readlink %s", template);
+ die_errno("cannot readlink '%s'", template);
if (sizeof(lnk) <= len)
die("insanely long symlink %s", template);
lnk[len] = 0;
if (symlink(lnk, path))
- die("cannot symlink %s %s", lnk, path);
+ die_errno("cannot symlink '%s' '%s'", lnk, path);
}
else if (S_ISREG(st_template.st_mode)) {
if (copy_file(path, template, st_template.st_mode))
- die("cannot copy %s to %s", template, path);
+ die_errno("cannot copy '%s' to '%s'", template,
+ path);
}
else
error("ignoring template %s", template);
@@ -350,7 +351,7 @@ static int guess_repository_type(const char *git_dir)
if (!strcmp(".", git_dir))
return 1;
if (!getcwd(cwd, sizeof(cwd)))
- die("cannot tell cwd");
+ die_errno("cannot tell cwd");
if (!strcmp(git_dir, cwd))
return 1;
/*
@@ -440,11 +441,11 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
if (!git_work_tree_cfg) {
git_work_tree_cfg = xcalloc(PATH_MAX, 1);
if (!getcwd(git_work_tree_cfg, PATH_MAX))
- die ("Cannot access current working directory.");
+ die_errno ("Cannot access current working directory");
}
if (access(get_git_work_tree(), X_OK))
- die ("Cannot access work tree '%s'",
- get_git_work_tree());
+ die_errno ("Cannot access work tree '%s'",
+ get_git_work_tree());
}
set_git_dir(make_absolute_path(git_dir));