Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
utils: makedirs - don't call chmod() in makedirs() when mode is ok
  • Loading branch information
perexg committed Feb 4, 2016
1 parent 99f0a45 commit e774324
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/utils.c
Expand Up @@ -481,6 +481,8 @@ md5sum ( const char *str )
return ret;
}

#define FILE_MODE_BITS(x) (x&(S_IRWXU|S_IRWXG|S_IRWXO))

int
makedirs ( const char *inpath, int mode, gid_t gid, uid_t uid )
{
Expand All @@ -503,7 +505,8 @@ makedirs ( const char *inpath, int mode, gid_t gid, uid_t uid )
err = mkdir(path, mode);
if (!err && gid != -1 && uid != -1)
err = chown(path, uid, gid);
if (!err)
if (!err && !stat(path, &st) &&
FILE_MODE_BITS(mode) != FILE_MODE_BITS(st.st_mode))
err = chmod(path, mode); /* override umode */
tvhtrace("settings", "Creating directory \"%s\" with octal permissions "
"\"%o\" gid %d uid %d", path, mode, gid, uid);
Expand Down

0 comments on commit e774324

Please sign in to comment.