Merge branch 'tb/shared-perm'
Simplifies adjust_shared_perm() implementation. * tb/shared-perm: path.c: optimize adjust_shared_perm() path.c: simplify adjust_shared_perm()
This commit is contained in:
commit
e65cdde454
3
cache.h
3
cache.h
@ -719,8 +719,7 @@ enum sharedrepo {
|
|||||||
PERM_EVERYBODY = 0664
|
PERM_EVERYBODY = 0664
|
||||||
};
|
};
|
||||||
int git_config_perm(const char *var, const char *value);
|
int git_config_perm(const char *var, const char *value);
|
||||||
int set_shared_perm(const char *path, int mode);
|
int adjust_shared_perm(const char *path);
|
||||||
#define adjust_shared_perm(path) set_shared_perm((path), 0)
|
|
||||||
int safe_create_leading_directories(char *path);
|
int safe_create_leading_directories(char *path);
|
||||||
int safe_create_leading_directories_const(const char *path);
|
int safe_create_leading_directories_const(const char *path);
|
||||||
int mkdir_in_gitdir(const char *path);
|
int mkdir_in_gitdir(const char *path);
|
||||||
|
57
path.c
57
path.c
@ -1,14 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* I'm tired of doing "vsnprintf()" etc just to open a
|
* Utilities for paths and pathnames
|
||||||
* file, so here's a "return static buffer with printf"
|
|
||||||
* interface for paths.
|
|
||||||
*
|
|
||||||
* It's obviously not thread-safe. Sue me. But it's quite
|
|
||||||
* useful for doing things like
|
|
||||||
*
|
|
||||||
* f = open(mkpath("%s/%s.git", base, name), O_RDONLY);
|
|
||||||
*
|
|
||||||
* which is what it's designed for.
|
|
||||||
*/
|
*/
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
@ -405,26 +396,14 @@ const char *enter_repo(const char *path, int strict)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int set_shared_perm(const char *path, int mode)
|
static int calc_shared_perm(int mode)
|
||||||
{
|
{
|
||||||
int tweak, shared, orig_mode;
|
int tweak;
|
||||||
|
|
||||||
if (!shared_repository) {
|
|
||||||
if (mode)
|
|
||||||
return chmod(path, mode & ~S_IFMT);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (!mode) {
|
|
||||||
if (get_st_mode_bits(path, &mode) < 0)
|
|
||||||
return -1;
|
|
||||||
orig_mode = mode;
|
|
||||||
} else
|
|
||||||
orig_mode = 0;
|
|
||||||
if (shared_repository < 0)
|
if (shared_repository < 0)
|
||||||
shared = -shared_repository;
|
tweak = -shared_repository;
|
||||||
else
|
else
|
||||||
shared = shared_repository;
|
tweak = shared_repository;
|
||||||
tweak = shared;
|
|
||||||
|
|
||||||
if (!(mode & S_IWUSR))
|
if (!(mode & S_IWUSR))
|
||||||
tweak &= ~0222;
|
tweak &= ~0222;
|
||||||
@ -436,16 +415,28 @@ int set_shared_perm(const char *path, int mode)
|
|||||||
else
|
else
|
||||||
mode |= tweak;
|
mode |= tweak;
|
||||||
|
|
||||||
if (S_ISDIR(mode)) {
|
return mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int adjust_shared_perm(const char *path)
|
||||||
|
{
|
||||||
|
int old_mode, new_mode;
|
||||||
|
|
||||||
|
if (!shared_repository)
|
||||||
|
return 0;
|
||||||
|
if (get_st_mode_bits(path, &old_mode) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
new_mode = calc_shared_perm(old_mode);
|
||||||
|
if (S_ISDIR(old_mode)) {
|
||||||
/* Copy read bits to execute bits */
|
/* Copy read bits to execute bits */
|
||||||
mode |= (shared & 0444) >> 2;
|
new_mode |= (new_mode & 0444) >> 2;
|
||||||
mode |= FORCE_DIR_SET_GID;
|
new_mode |= FORCE_DIR_SET_GID;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((shared_repository < 0
|
if (((old_mode ^ new_mode) & ~S_IFMT) &&
|
||||||
? (orig_mode & (FORCE_DIR_SET_GID | 0777))
|
chmod(path, (new_mode & ~S_IFMT)) < 0)
|
||||||
: (orig_mode & mode)) != mode) &&
|
|
||||||
chmod(path, (mode & ~S_IFMT)) < 0)
|
|
||||||
return -2;
|
return -2;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user