*: correct and codify various file permissions The following files now have 0444 permissions: - loose objects - pack indexes - pack files - packs downloaded by fetch - packs downloaded by the HTTP transport And the following files now have 0666 permissions: - config files - repository indexes - reflogs - refs This brings libgit2 more in line with Git. Note that git_filebuf_commit() and git_filebuf_commit_at() have both gained a new mode parameter. The latter change fixes an important issue where filebufs created with GIT_FILEBUF_TEMPORARY received 0600 permissions (due to mkstemp(3) usage). Now we chmod() the file before renaming it into place. Tests have been added to confirm that new commit, tag, and tree objects are created with the right permissions. I don't have access to Windows, so for now I've guarded the tests with "#ifndef GIT_WIN32".
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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
diff --git a/src/config.h b/src/config.h
index 7749a9c..43574a5 100644
--- a/src/config.h
+++ b/src/config.h
@@ -14,6 +14,7 @@
#define GIT_CONFIG_FILENAME ".gitconfig"
#define GIT_CONFIG_FILENAME_INREPO "config"
+#define GIT_CONFIG_FILE_MODE 0666
struct git_config {
git_vector files;
diff --git a/src/config_file.c b/src/config_file.c
index a85ae15..855574d 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -1034,7 +1034,7 @@ static int config_write(diskfile_backend *cfg, cvar_t *var)
if (error < GIT_SUCCESS)
git_filebuf_cleanup(&file);
else
- error = git_filebuf_commit(&file);
+ error = git_filebuf_commit(&file, GIT_CONFIG_FILE_MODE);
git_futils_freebuffer(&cfg->reader.buffer);
return error;
diff --git a/src/fetch.c b/src/fetch.c
index ac72828..af7dbaf 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -14,6 +14,7 @@
#include "transport.h"
#include "remote.h"
#include "refspec.h"
+#include "pack.h"
#include "fetch.h"
#include "netops.h"
@@ -181,7 +182,7 @@ int git_fetch__download_pack(char **out, const char *buffered, size_t buffered_s
}
/* A bit dodgy, but we need to keep the pack at the temporary path */
- error = git_filebuf_commit_at(&file, file.path_lock);
+ error = git_filebuf_commit_at(&file, file.path_lock, GIT_PACK_FILE_MODE);
cleanup:
if (error < GIT_SUCCESS)
git_filebuf_cleanup(&file);
diff --git a/src/filebuf.c b/src/filebuf.c
index e6167d0..a86d25b 100644
--- a/src/filebuf.c
+++ b/src/filebuf.c
@@ -10,6 +10,8 @@
#include "filebuf.h"
#include "fileops.h"
+#define GIT_LOCK_FILE_MODE 0644
+
static const size_t WRITE_BUFFER_SIZE = (4096 * 2);
static int lock_file(git_filebuf *file, int flags)
@@ -24,9 +26,9 @@ static int lock_file(git_filebuf *file, int flags)
/* create path to the file buffer is required */
if (flags & GIT_FILEBUF_FORCE) {
/* XXX: Should dirmode here be configurable? Or is 0777 always fine? */
- file->fd = git_futils_creat_locked_withpath(file->path_lock, 0777, 0644);
+ file->fd = git_futils_creat_locked_withpath(file->path_lock, 0777, GIT_LOCK_FILE_MODE);
} else {
- file->fd = git_futils_creat_locked(file->path_lock, 0644);
+ file->fd = git_futils_creat_locked(file->path_lock, GIT_LOCK_FILE_MODE);
}
if (file->fd < 0)
@@ -247,17 +249,17 @@ int git_filebuf_hash(git_oid *oid, git_filebuf *file)
return GIT_SUCCESS;
}
-int git_filebuf_commit_at(git_filebuf *file, const char *path)
+int git_filebuf_commit_at(git_filebuf *file, const char *path, mode_t mode)
{
free(file->path_original);
file->path_original = git__strdup(path);
if (file->path_original == NULL)
return GIT_ENOMEM;
- return git_filebuf_commit(file);
+ return git_filebuf_commit(file, mode);
}
-int git_filebuf_commit(git_filebuf *file)
+int git_filebuf_commit(git_filebuf *file, mode_t mode)
{
int error;
@@ -271,6 +273,11 @@ int git_filebuf_commit(git_filebuf *file)
p_close(file->fd);
file->fd = -1;
+ if (p_chmod(file->path_lock, mode)) {
+ error = git__throw(GIT_EOSERR, "Failed to chmod locked file before committing");
+ goto cleanup;
+ }
+
error = git_futils_mv_atomic(file->path_lock, file->path_original);
cleanup:
diff --git a/src/filebuf.h b/src/filebuf.h
index 525ca3c..d08505e 100644
--- a/src/filebuf.h
+++ b/src/filebuf.h
@@ -49,8 +49,8 @@ int git_filebuf_reserve(git_filebuf *file, void **buff, size_t len);
int git_filebuf_printf(git_filebuf *file, const char *format, ...) GIT_FORMAT_PRINTF(2, 3);
int git_filebuf_open(git_filebuf *lock, const char *path, int flags);
-int git_filebuf_commit(git_filebuf *lock);
-int git_filebuf_commit_at(git_filebuf *lock, const char *path);
+int git_filebuf_commit(git_filebuf *lock, mode_t mode);
+int git_filebuf_commit_at(git_filebuf *lock, const char *path, mode_t mode);
void git_filebuf_cleanup(git_filebuf *lock);
int git_filebuf_hash(git_oid *oid, git_filebuf *file);
diff --git a/src/index.c b/src/index.c
index 7bf5daf..2655aef 100644
--- a/src/index.c
+++ b/src/index.c
@@ -262,7 +262,7 @@ int git_index_write(git_index *index)
return git__rethrow(error, "Failed to write index");
}
- if ((error = git_filebuf_commit(&file)) < GIT_SUCCESS)
+ if ((error = git_filebuf_commit(&file, GIT_INDEX_FILE_MODE)) < GIT_SUCCESS)
return git__rethrow(error, "Failed to write index");
if (p_stat(index->index_file_path, &indexst) == 0) {
diff --git a/src/index.h b/src/index.h
index e912770..a1cd340 100644
--- a/src/index.h
+++ b/src/index.h
@@ -14,6 +14,9 @@
#include "git2/odb.h"
#include "git2/index.h"
+#define GIT_INDEX_FILE "index"
+#define GIT_INDEX_FILE_MODE 0666
+
struct git_index {
git_repository *repository;
char *index_file_path;
diff --git a/src/indexer.c b/src/indexer.c
index d5f605f..6be4f4a 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -272,7 +272,7 @@ int git_indexer_write(git_indexer *idx)
/* Figure out what the final name should be */
index_path(filename, idx);
/* Commit file */
- error = git_filebuf_commit_at(&idx->file, filename);
+ error = git_filebuf_commit_at(&idx->file, filename, GIT_PACK_FILE_MODE);
cleanup:
git_mwindow_free_all(&idx->pack->mwf);
diff --git a/src/odb.h b/src/odb.h
index 7c8c9f9..833739e 100644
--- a/src/odb.h
+++ b/src/odb.h
@@ -16,6 +16,7 @@
#define GIT_OBJECTS_DIR "objects/"
#define GIT_OBJECT_DIR_MODE 0777
+#define GIT_OBJECT_FILE_MODE 0444
/* DO NOT EXPORT */
typedef struct {
diff --git a/src/odb_loose.c b/src/odb_loose.c
index a3013d3..dc98972 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -670,7 +670,7 @@ static int loose_backend__stream_fwrite(git_oid *oid, git_odb_stream *_stream)
return git__rethrow(error, "Failed to write loose backend");
stream->finished = 1;
- return git_filebuf_commit_at(&stream->fbuf, final_path);
+ return git_filebuf_commit_at(&stream->fbuf, final_path, GIT_OBJECT_FILE_MODE);
}
static int loose_backend__stream_write(git_odb_stream *_stream, const char *data, size_t len)
@@ -790,7 +790,7 @@ static int loose_backend__write(git_oid *oid, git_odb_backend *_backend, const v
if ((error = git_futils_mkpath2file(final_path, GIT_OBJECT_DIR_MODE)) < GIT_SUCCESS)
goto cleanup;
- return git_filebuf_commit_at(&fbuf, final_path);
+ return git_filebuf_commit_at(&fbuf, final_path, GIT_OBJECT_FILE_MODE);
cleanup:
git_filebuf_cleanup(&fbuf);
diff --git a/src/pack.h b/src/pack.h
index 0fddd9d..aecf580 100644
--- a/src/pack.h
+++ b/src/pack.h
@@ -15,6 +15,8 @@
#include "mwindow.h"
#include "odb.h"
+#define GIT_PACK_FILE_MODE 0444
+
#define PACK_SIGNATURE 0x5041434b /* "PACK" */
#define PACK_VERSION 2
#define pack_version_ok(v) ((v) == htonl(2) || (v) == htonl(3))
diff --git a/src/reflog.c b/src/reflog.c
index 6cdb353..303c2b4 100644
--- a/src/reflog.c
+++ b/src/reflog.c
@@ -71,7 +71,7 @@ static int reflog_write(const char *log_path, const char *oid_old,
}
git_filebuf_write(&fbuf, log.ptr, log.size);
- error = git_filebuf_commit(&fbuf);
+ error = git_filebuf_commit(&fbuf, GIT_REFLOG_FILE_MODE);
git_buf_free(&log);
return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to write reflog");
diff --git a/src/reflog.h b/src/reflog.h
index 16e9a94..44b0637 100644
--- a/src/reflog.h
+++ b/src/reflog.h
@@ -13,6 +13,7 @@
#define GIT_REFLOG_DIR "logs/"
#define GIT_REFLOG_DIR_MODE 0777
+#define GIT_REFLOG_FILE_MODE 0666
#define GIT_REFLOG_SIZE_MIN (2*GIT_OID_HEXSZ+2+17)
diff --git a/src/refs.c b/src/refs.c
index fcf771b..b34067f 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -9,6 +9,7 @@
#include "hash.h"
#include "repository.h"
#include "fileops.h"
+#include "pack.h"
#include <git2/tag.h>
#include <git2/object.h>
@@ -357,7 +358,7 @@ static int loose_write(git_reference *ref)
goto unlock;
}
- error = git_filebuf_commit(&file);
+ error = git_filebuf_commit(&file, GIT_REFS_FILE_MODE);
if (p_stat(ref_path, &st) == GIT_SUCCESS)
ref->mtime = st.st_mtime;
@@ -870,7 +871,7 @@ cleanup:
/* if we've written all the references properly, we can commit
* the packfile to make the changes effective */
if (error == GIT_SUCCESS) {
- error = git_filebuf_commit(&pack_file);
+ error = git_filebuf_commit(&pack_file, GIT_PACK_FILE_MODE);
/* when and only when the packfile has been properly written,
* we can go ahead and remove the loose refs */
diff --git a/src/refs.h b/src/refs.h
index f802cfe..33c1e69 100644
--- a/src/refs.h
+++ b/src/refs.h
@@ -17,6 +17,7 @@
#define GIT_REFS_TAGS_DIR GIT_REFS_DIR "tags/"
#define GIT_REFS_REMOTES_DIR GIT_REFS_DIR "remotes/"
#define GIT_REFS_DIR_MODE 0777
+#define GIT_REFS_FILE_MODE 0666
#define GIT_RENAMED_REF_FILE GIT_REFS_DIR "RENAMED-REF"
diff --git a/src/repository.h b/src/repository.h
index a12dd9d..0c17958 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -24,7 +24,6 @@
#define GIT_DIR DOT_GIT "/"
#define GIT_DIR_MODE 0755
#define GIT_BARE_DIR_MODE 0777
-#define GIT_INDEX_FILE "index"
struct git_object {
git_cached_obj cached;
diff --git a/src/transports/http.c b/src/transports/http.c
index 680354b..c324bb4 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -15,6 +15,7 @@
#include "buffer.h"
#include "pkt.h"
#include "refs.h"
+#include "pack.h"
#include "fetch.h"
#include "filebuf.h"
#include "repository.h"
@@ -702,7 +703,7 @@ static int http_download_pack(char **out, git_transport *transport, git_reposito
}
/* A bit dodgy, but we need to keep the pack at the temporary path */
- error = git_filebuf_commit_at(&file, file.path_lock);
+ error = git_filebuf_commit_at(&file, file.path_lock, GIT_PACK_FILE_MODE);
cleanup:
if (error < GIT_SUCCESS)
diff --git a/tests-clay/core/dirent.c b/tests-clay/core/dirent.c
index 898b122..105e8d8 100644
--- a/tests-clay/core/dirent.c
+++ b/tests-clay/core/dirent.c
@@ -31,7 +31,7 @@ static void setup(walk_data *d)
state_loc = d;
for (n = d->names; n->name; n++) {
- git_file fd = p_creat(n->name, 0600);
+ git_file fd = p_creat(n->name, 0666);
cl_assert(fd >= 0);
p_close(fd);
n->count = 0;
diff --git a/tests-clay/core/filebuf.c b/tests-clay/core/filebuf.c
index e00e204..e1ecb27 100644
--- a/tests-clay/core/filebuf.c
+++ b/tests-clay/core/filebuf.c
@@ -27,14 +27,14 @@ void test_core_filebuf__1(void)
int fd;
char test[] = "test";
- fd = p_creat(test, 0644);
+ fd = p_creat(test, 0666);
cl_must_pass(fd);
cl_must_pass(p_write(fd, "libgit2 rocks\n", 14));
cl_must_pass(p_close(fd));
cl_git_pass(git_filebuf_open(&file, test, GIT_FILEBUF_APPEND));
cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks"));
- cl_git_pass(git_filebuf_commit(&file));
+ cl_git_pass(git_filebuf_commit(&file, 0666));
cl_must_pass(p_unlink(test));
}
@@ -51,7 +51,7 @@ void test_core_filebuf__2(void)
cl_git_pass(git_filebuf_open(&file, test, 0));
cl_git_pass(git_filebuf_write(&file, buf, sizeof(buf)));
- cl_git_pass(git_filebuf_commit(&file));
+ cl_git_pass(git_filebuf_commit(&file, 0666));
cl_must_pass(p_unlink(test));
}
diff --git a/tests-clay/core/rmdir.c b/tests-clay/core/rmdir.c
index 03baecf..20cc8f5 100644
--- a/tests-clay/core/rmdir.c
+++ b/tests-clay/core/rmdir.c
@@ -39,7 +39,7 @@ void test_core_rmdir__fail_to_delete_non_empty_dir(void)
git_path_join(file, empty_tmp_dir, "/two/file.txt");
- fd = p_creat(file, 0755);
+ fd = p_creat(file, 0666);
cl_assert(fd >= 0);
cl_must_pass(p_close(fd));
diff --git a/tests-clay/status/single.c b/tests-clay/status/single.c
index ea1c77f..4fd6e6f 100644
--- a/tests-clay/status/single.c
+++ b/tests-clay/status/single.c
@@ -10,7 +10,7 @@ cleanup__remove_file(void *_file)
static void
file_create(const char *filename, const char *content)
{
- int fd = p_creat(filename, 0644);
+ int fd = p_creat(filename, 0666);
cl_assert(fd >= 0);
cl_must_pass(p_write(fd, content, strlen(content)));
cl_must_pass(p_close(fd));
diff --git a/tests/t00-core.c b/tests/t00-core.c
index 1856815..dbc8067 100644
--- a/tests/t00-core.c
+++ b/tests/t00-core.c
@@ -264,7 +264,7 @@ static int setup(walk_data *d)
state_loc = d;
for (n = d->names; n->name; n++) {
- git_file fd = p_creat(n->name, 0600);
+ git_file fd = p_creat(n->name, 0666);
if (fd < 0)
return GIT_ERROR;
p_close(fd);
@@ -479,14 +479,14 @@ BEGIN_TEST(filebuf1, "make sure GIT_FILEBUF_APPEND works as expected")
int fd;
char test[] = "test";
- fd = p_creat(test, 0644);
+ fd = p_creat(test, 0666);
must_pass(fd);
must_pass(p_write(fd, "libgit2 rocks\n", 14));
must_pass(p_close(fd));
must_pass(git_filebuf_open(&file, test, GIT_FILEBUF_APPEND));
must_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks"));
- must_pass(git_filebuf_commit(&file));
+ must_pass(git_filebuf_commit(&file, 0666));
must_pass(p_unlink(test));
END_TEST
@@ -499,7 +499,7 @@ BEGIN_TEST(filebuf2, "make sure git_filebuf_write writes large buffer correctly"
memset(buf, 0xfe, sizeof(buf));
must_pass(git_filebuf_open(&file, test, 0));
must_pass(git_filebuf_write(&file, buf, sizeof(buf)));
- must_pass(git_filebuf_commit(&file));
+ must_pass(git_filebuf_commit(&file, 0666));
must_pass(p_unlink(test));
END_TEST
diff --git a/tests/t04-commit.c b/tests/t04-commit.c
index 3fb4d37..4abbf01 100644
--- a/tests/t04-commit.c
+++ b/tests/t04-commit.c
@@ -690,6 +690,10 @@ BEGIN_TEST(write0, "write a new commit object from memory to disk")
must_be_true(strcmp(git_commit_message(commit), COMMIT_MESSAGE) == 0);
+#ifndef GIT_WIN32
+ must_be_true((loose_object_mode(REPOSITORY_FOLDER, (git_object *)commit) & 0777) == GIT_OBJECT_FILE_MODE);
+#endif
+
must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit));
git_commit_close(commit);
diff --git a/tests/t06-index.c b/tests/t06-index.c
index dde98ab..44562d0 100644
--- a/tests/t06-index.c
+++ b/tests/t06-index.c
@@ -179,7 +179,7 @@ BEGIN_TEST(add0, "add a new file to the index")
must_pass(git_futils_mkpath2file(TEMP_REPO_FOLDER "myrepo/test.txt", 0777));
must_pass(git_filebuf_open(&file, TEMP_REPO_FOLDER "myrepo/test.txt", 0));
must_pass(git_filebuf_write(&file, "hey there\n", 10));
- must_pass(git_filebuf_commit(&file));
+ must_pass(git_filebuf_commit(&file, 0666));
/* Store the expected hash of the file/blob
* This has been generated by executing the following
diff --git a/tests/t08-tag.c b/tests/t08-tag.c
index 216fb9d..85ef922 100644
--- a/tests/t08-tag.c
+++ b/tests/t08-tag.c
@@ -189,6 +189,9 @@ BEGIN_TEST(write0, "write a tag to the repository and read it again")
must_pass(git_reference_lookup(&ref_tag, repo, "refs/tags/the-tag"));
must_be_true(git_oid_cmp(git_reference_oid(ref_tag), &tag_id) == 0);
must_pass(git_reference_delete(ref_tag));
+#ifndef GIT_WIN32
+ must_be_true((loose_object_mode(REPOSITORY_FOLDER, (git_object *)tag) & 0777) == GIT_OBJECT_FILE_MODE);
+#endif
must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)tag));
diff --git a/tests/t09-tree.c b/tests/t09-tree.c
index 1f2fe3f..2341a1c 100644
--- a/tests/t09-tree.c
+++ b/tests/t09-tree.c
@@ -202,6 +202,7 @@ BEGIN_TEST(write3, "write a hierarchical tree from a memory")
must_be_true(2 == git_tree_entrycount(tree));
#ifndef GIT_WIN32
must_be_true((loose_object_dir_mode(TEMP_REPO_FOLDER, (git_object *)tree) & 0777) == GIT_OBJECT_DIR_MODE);
+ must_be_true((loose_object_mode(TEMP_REPO_FOLDER, (git_object *)tree) & 0777) == GIT_OBJECT_FILE_MODE);
#endif
git_tree_close(tree);
diff --git a/tests/t12-repo.c b/tests/t12-repo.c
index c07150c..6197cdd 100644
--- a/tests/t12-repo.c
+++ b/tests/t12-repo.c
@@ -351,7 +351,7 @@ static int write_file(const char *path, const char *content)
return error;
}
- file = git_futils_creat_withpath(path, 0777, 0644);
+ file = git_futils_creat_withpath(path, 0777, 0666);
if (file < GIT_SUCCESS)
return file;
diff --git a/tests/t15-config.c b/tests/t15-config.c
index c4cb590..a97f820 100644
--- a/tests/t15-config.c
+++ b/tests/t15-config.c
@@ -319,7 +319,7 @@ BEGIN_TEST(config16, "add a variable in a new section")
/* As the section wasn't removed, owerwrite the file */
must_pass(git_filebuf_open(&buf, CONFIG_BASE "/config10", 0));
must_pass(git_filebuf_write(&buf, "[empty]\n", strlen("[empty]\n")));
- must_pass(git_filebuf_commit(&buf));
+ must_pass(git_filebuf_commit(&buf, 0666));
END_TEST
BEGIN_TEST(config17, "prefixes aren't broken")
diff --git a/tests/t18-status.c b/tests/t18-status.c
index bd205a4..d836fb9 100644
--- a/tests/t18-status.c
+++ b/tests/t18-status.c
@@ -37,7 +37,7 @@ static int file_create(const char *filename, const char *content)
{
int fd;
- fd = p_creat(filename, 0644);
+ fd = p_creat(filename, 0666);
if (fd == 0)
return GIT_ERROR;
if (p_write(fd, content, strlen(content)) != 0)
@@ -400,7 +400,7 @@ BEGIN_TEST(singlestatus3, "test retrieving status for a new file in an empty rep
must_pass(remove_placeholders(TEST_STD_REPO_FOLDER, "dummy-marker.txt"));
git_path_join(file_path, TEMP_REPO_FOLDER, filename);
- fd = p_creat(file_path, 0644);
+ fd = p_creat(file_path, 0666);
must_pass(fd);
must_pass(p_write(fd, "new_file\n", 9));
must_pass(p_close(fd));
diff --git a/tests/test_helpers.c b/tests/test_helpers.c
index 7074e48..7bba2e1 100644
--- a/tests/test_helpers.c
+++ b/tests/test_helpers.c
@@ -110,6 +110,18 @@ void locate_loose_object(const char *repository_folder, git_object *object, char
*out_folder = top_folder;
}
+int loose_object_mode(const char *repository_folder, git_object *object)
+{
+ char *object_path;
+ struct stat st;
+
+ locate_loose_object(repository_folder, object, &object_path, NULL);
+ assert(p_stat(object_path, &st) == 0);
+ free(object_path);
+
+ return st.st_mode;
+}
+
int loose_object_dir_mode(const char *repository_folder, git_object *object)
{
char *object_path;
@@ -175,7 +187,7 @@ int copy_file(const char *src, const char *dst)
if (git_futils_readbuffer(&source_buf, src) < GIT_SUCCESS)
return GIT_ENOTFOUND;
- dst_fd = git_futils_creat_withpath(dst, 0777, 0644);
+ dst_fd = git_futils_creat_withpath(dst, 0777, 0666);
if (dst_fd < 0)
goto cleanup;
diff --git a/tests/test_helpers.h b/tests/test_helpers.h
index 2e5194d..16a3a2c 100644
--- a/tests/test_helpers.h
+++ b/tests/test_helpers.h
@@ -65,6 +65,7 @@ extern int cmp_objects(git_rawobj *o, object_data *d);
extern void locate_loose_object(const char *odb_dir, git_object *object, char **out, char **out_folder);
+extern int loose_object_mode(const char *odb_dir, git_object *object);
extern int loose_object_dir_mode(const char *odb_dir, git_object *object);
extern int remove_loose_object(const char *odb_dir, git_object *object);