summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9fec8b2)
raw | patch | inline | side by side (parent: 9fec8b2)
author | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Sun, 17 Apr 2005 05:26:31 +0000 (22:26 -0700) | ||
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Sun, 17 Apr 2005 05:26:31 +0000 (22:26 -0700) |
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.
or not (by its owner). Everything else we leave for the user umask to
decide.
cache.h | patch | blob | history | |
checkout-cache.c | patch | blob | history | |
read-cache.c | patch | blob | history | |
read-tree.c | patch | blob | history | |
update-cache.c | patch | blob | history |
index 88c2fa8d95b2cf6c0b2cd78c074659885625766d..efeb82b6dcdca38008bb9ab6d2e1e207fc0aa698 100644 (file)
--- a/cache.h
+++ b/cache.h
#define ce_size(ce) cache_entry_size(ce_namelen(ce))
#define ce_stage(ce) ((CE_STAGEMASK & ntohs((ce)->ce_flags)) >> CE_STAGESHIFT)
+#define ce_permissions(mode) (((mode) & 0100) ? 0755 : 0644)
+#define create_ce_mode(mode) htonl(S_IFREG | ce_permissions(mode))
+
#define cache_entry_size(len) ((offsetof(struct cache_entry,name) + (len) + 8) & ~7)
const char *sha1_file_directory;
diff --git a/checkout-cache.c b/checkout-cache.c
index 8d5e4cd148f6111ab7e0bfb7f9142693e08f66bd..09b36b9c77e5ed3b833f7ede502640a966373f49 100644 (file)
--- a/checkout-cache.c
+++ b/checkout-cache.c
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)
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);
}
diff --git a/read-cache.c b/read-cache.c
index 5b4ab03d27826445a7b02a89de9d5106619e713a..21f6e8e4d5350d405e210c42c6d005eb314275ba 100644 (file)
--- a/read-cache.c
+++ b/read-cache.c
if (ce->ce_uid != htonl(st->st_uid) ||
ce->ce_gid != htonl(st->st_gid))
changed |= OWNER_CHANGED;
- if (ce->ce_mode != htonl(st->st_mode))
+ /* We consider only the owner x bit to be relevant for "mode changes" */
+ if (0100 & (ntohs(ce->ce_mode) ^ st->st_mode))
changed |= MODE_CHANGED;
if (ce->ce_dev != htonl(st->st_dev) ||
ce->ce_ino != htonl(st->st_ino))
diff --git a/read-tree.c b/read-tree.c
index c4ca86f48607cc7f83b88739a539b30315b4cc12..f507f1633cf4a74ec5086ab8561684a03dbb9bd9 100644 (file)
--- a/read-tree.c
+++ b/read-tree.c
memset(ce, 0, size);
- ce->ce_mode = htonl(mode);
+ ce->ce_mode = create_ce_mode(mode);
ce->ce_flags = create_ce_flags(baselen + len, stage);
memcpy(ce->name, base, baselen);
memcpy(ce->name + baselen, pathname, len+1);
diff --git a/update-cache.c b/update-cache.c
index 134ba7439891d698c4b82223a9e872d3a77e5edb..7d1d8e512617dc4a3b77a922f2765e79201895ab 100644 (file)
--- a/update-cache.c
+++ b/update-cache.c
memset(ce, 0, size);
memcpy(ce->name, path, namelen);
fill_stat_cache_info(ce, &st);
- ce->ce_mode = htonl(st.st_mode);
+ ce->ce_mode = create_ce_mode(st.st_mode);
ce->ce_flags = htons(namelen);
if (index_fd(path, namelen, ce, fd, &st) < 0)
memcpy(ce->sha1, sha1, 20);
memcpy(ce->name, arg3, len);
ce->ce_flags = htons(len);
- ce->ce_mode = htonl(mode);
+ ce->ce_mode = create_ce_mode(mode);
return add_cache_entry(ce, allow_add);
}