convert all remaining instances of chmod(2) to fchmod(2) ok stsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
diff --git a/lib/object_create.c b/lib/object_create.c
index a1f3f64..71e76e0 100644
--- a/lib/object_create.c
+++ b/lib/object_create.c
@@ -78,6 +78,11 @@ create_object_file(struct got_object_id *id, FILE *content,
goto done;
}
+ if (fchmod(fileno(tmpfile), GOT_DEFAULT_FILE_MODE) != 0) {
+ err = got_error_from_errno2("fchmod", tmppath);
+ goto done;
+ }
+
err = got_deflate_to_file(&tmplen, content, tmpfile);
if (err)
goto done;
@@ -92,11 +97,6 @@ create_object_file(struct got_object_id *id, FILE *content,
}
free(tmppath);
tmppath = NULL;
-
- if (chmod(objpath, GOT_DEFAULT_FILE_MODE) != 0) {
- err = got_error_from_errno2("chmod", objpath);
- goto done;
- }
done:
free(objpath);
if (tmppath) {
diff --git a/lib/reference.c b/lib/reference.c
index 2b33b7d..6df30b6 100644
--- a/lib/reference.c
+++ b/lib/reference.c
@@ -1140,17 +1140,17 @@ got_ref_write(struct got_reference *ref, struct got_repository *repo)
sb.st_mode = GOT_DEFAULT_FILE_MODE;
}
+ if (fchmod(fileno(f), sb.st_mode) != 0) {
+ err = got_error_from_errno2("fchmod", tmppath);
+ goto done;
+ }
+
if (rename(tmppath, path) != 0) {
err = got_error_from_errno3("rename", tmppath, path);
goto done;
}
free(tmppath);
tmppath = NULL;
-
- if (chmod(path, sb.st_mode) != 0) {
- err = got_error_from_errno2("chmod", path);
- goto done;
- }
done:
if (ref->lf == NULL && lf)
unlock_err = got_lockfile_unlock(lf);
@@ -1276,23 +1276,22 @@ delete_packed_ref(struct got_reference *delref, struct got_repository *repo)
goto done;
}
- if (stat(packed_refs_path, &sb) != 0) {
+ if (fstat(fileno(f), &sb) != 0) {
if (errno != ENOENT) {
- err = got_error_from_errno2("stat",
+ err = got_error_from_errno2("fstat",
packed_refs_path);
goto done;
}
sb.st_mode = GOT_DEFAULT_FILE_MODE;
}
- if (rename(tmppath, packed_refs_path) != 0) {
- err = got_error_from_errno3("rename", tmppath,
- packed_refs_path);
+ if (fchmod(fileno(tmpf), sb.st_mode) != 0) {
+ err = got_error_from_errno2("fchmod", tmppath);
goto done;
}
- if (chmod(packed_refs_path, sb.st_mode) != 0) {
- err = got_error_from_errno2("chmod",
+ if (rename(tmppath, packed_refs_path) != 0) {
+ err = got_error_from_errno3("rename", tmppath,
packed_refs_path);
goto done;
}
diff --git a/lib/worktree.c b/lib/worktree.c
index 54a1c38..3d3b938 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -968,6 +968,11 @@ install_symlink_conflict(const char *deriv_target,
if (err)
goto done;
+ if (fchmod(fileno(f), GOT_DEFAULT_FILE_MODE) == -1) {
+ err = got_error_from_errno2("fchmod", path);
+ goto done;
+ }
+
if (fprintf(f, "%s %s\n%s\n%s%s%s%s%s\n%s\n%s\n",
GOT_DIFF_CONFLICT_MARKER_BEGIN, label_deriv,
deriv_target ? deriv_target : "(symlink was deleted)",
@@ -989,10 +994,6 @@ install_symlink_conflict(const char *deriv_target,
err = got_error_from_errno3("rename", path, ondisk_path);
goto done;
}
- if (chmod(ondisk_path, GOT_DEFAULT_FILE_MODE) == -1) {
- err = got_error_from_errno2("chmod", ondisk_path);
- goto done;
- }
done:
if (f != NULL && fclose(f) == EOF && err == NULL)
err = got_error_from_errno2("fclose", path);
@@ -1511,6 +1512,12 @@ install_blob(struct got_worktree *worktree, const char *ondisk_path,
return got_error_from_errno2("open", ondisk_path);
}
+ if (fchmod(fd, get_ondisk_perms(te_mode & S_IXUSR, st_mode)) == -1) {
+ err = got_error_from_errno2("fchmod",
+ update ? tmppath : ondisk_path);
+ goto done;
+ }
+
if (progress_cb) {
if (restoring_missing_file)
err = (*progress_cb)(progress_arg, GOT_STATUS_MISSING,
@@ -1559,12 +1566,6 @@ install_blob(struct got_worktree *worktree, const char *ondisk_path,
}
}
- if (chmod(ondisk_path,
- get_ondisk_perms(te_mode & S_IXUSR, st_mode)) == -1) {
- err = got_error_from_errno2("chmod", ondisk_path);
- goto done;
- }
-
done:
if (fd != -1 && close(fd) != 0 && err == NULL)
err = got_error_from_errno("close");
@@ -4332,8 +4333,8 @@ create_patched_content(char **path_outfile, int reverse_patch,
goto done;
if (!S_ISLNK(sb2.st_mode)) {
- if (chmod(*path_outfile, sb2.st_mode) == -1) {
- err = got_error_from_errno2("chmod", path2);
+ if (fchmod(fileno(outfile), sb2.st_mode) == -1) {
+ err = got_error_from_errno2("fchmod", path2);
goto done;
}
}