From e44794706eeb57f2ee38ed1604821aa38b8ad9d2 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sat, 16 Apr 2005 22:26:31 -0700 Subject: Be much more liberal about the file mode bits. We only really care about the difference between a file being executable or not (by its owner). Everything else we leave for the user umask to decide. --- checkout-cache.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'checkout-cache.c') diff --git a/checkout-cache.c b/checkout-cache.c index 8d5e4cd148..09b36b9c77 100644 --- a/checkout-cache.c +++ b/checkout-cache.c @@ -52,11 +52,14 @@ static void create_directories(const char *path) static int create_file(const char *path, unsigned int mode) { - int fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0600); + int fd; + + mode = (mode & 0100) ? 777 : 666; + fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, mode); if (fd < 0) { if (errno == ENOENT) { create_directories(path); - fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0600); + fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, mode); } } if (fd >= 0) @@ -104,6 +107,14 @@ static int checkout_entry(struct cache_entry *ce) fprintf(stderr, "checkout-cache: %s already exists\n", ce->name); return 0; } + + /* + * We unlink the old file, to get the new one with the + * right permissions (including umask, which is nasty + * to emulate by hand - much easier to let the system + * just do the right thing) + */ + unlink(ce->name); } return write_entry(ce); } -- cgit v1.2.1