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.maint
parent
9fec8b26ef
commit
e44794706e
3
cache.h
3
cache.h
|
@ -72,6 +72,9 @@ struct cache_entry {
|
||||||
#define ce_size(ce) cache_entry_size(ce_namelen(ce))
|
#define ce_size(ce) cache_entry_size(ce_namelen(ce))
|
||||||
#define ce_stage(ce) ((CE_STAGEMASK & ntohs((ce)->ce_flags)) >> CE_STAGESHIFT)
|
#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)
|
#define cache_entry_size(len) ((offsetof(struct cache_entry,name) + (len) + 8) & ~7)
|
||||||
|
|
||||||
const char *sha1_file_directory;
|
const char *sha1_file_directory;
|
|
@ -52,11 +52,14 @@ static void create_directories(const char *path)
|
||||||
|
|
||||||
static int create_file(const char *path, unsigned int mode)
|
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 (fd < 0) {
|
||||||
if (errno == ENOENT) {
|
if (errno == ENOENT) {
|
||||||
create_directories(path);
|
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)
|
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);
|
fprintf(stderr, "checkout-cache: %s already exists\n", ce->name);
|
||||||
return 0;
|
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);
|
return write_entry(ce);
|
||||||
}
|
}
|
|
@ -303,7 +303,8 @@ int cache_match_stat(struct cache_entry *ce, struct stat *st)
|
||||||
if (ce->ce_uid != htonl(st->st_uid) ||
|
if (ce->ce_uid != htonl(st->st_uid) ||
|
||||||
ce->ce_gid != htonl(st->st_gid))
|
ce->ce_gid != htonl(st->st_gid))
|
||||||
changed |= OWNER_CHANGED;
|
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;
|
changed |= MODE_CHANGED;
|
||||||
if (ce->ce_dev != htonl(st->st_dev) ||
|
if (ce->ce_dev != htonl(st->st_dev) ||
|
||||||
ce->ce_ino != htonl(st->st_ino))
|
ce->ce_ino != htonl(st->st_ino))
|
|
@ -15,7 +15,7 @@ static int read_one_entry(unsigned char *sha1, const char *base, int baselen, co
|
||||||
|
|
||||||
memset(ce, 0, size);
|
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);
|
ce->ce_flags = create_ce_flags(baselen + len, stage);
|
||||||
memcpy(ce->name, base, baselen);
|
memcpy(ce->name, base, baselen);
|
||||||
memcpy(ce->name + baselen, pathname, len+1);
|
memcpy(ce->name + baselen, pathname, len+1);
|
|
@ -106,7 +106,7 @@ static int add_file_to_cache(char *path)
|
||||||
memset(ce, 0, size);
|
memset(ce, 0, size);
|
||||||
memcpy(ce->name, path, namelen);
|
memcpy(ce->name, path, namelen);
|
||||||
fill_stat_cache_info(ce, &st);
|
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);
|
ce->ce_flags = htons(namelen);
|
||||||
|
|
||||||
if (index_fd(path, namelen, ce, fd, &st) < 0)
|
if (index_fd(path, namelen, ce, fd, &st) < 0)
|
||||||
|
@ -260,7 +260,7 @@ static int add_cacheinfo(char *arg1, char *arg2, char *arg3)
|
||||||
memcpy(ce->sha1, sha1, 20);
|
memcpy(ce->sha1, sha1, 20);
|
||||||
memcpy(ce->name, arg3, len);
|
memcpy(ce->name, arg3, len);
|
||||||
ce->ce_flags = htons(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);
|
return add_cache_entry(ce, allow_add);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue