diff options
author | Matt Kraai <kraai@debian.org> | 2001-04-30 21:32:43 +0400 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2001-04-30 21:32:43 +0400 |
commit | 218aa370b487b630953fdf2f1e9be26aa232de8a (patch) | |
tree | f050bb45b13ccde534cf98c988d733292969ebdb /libbb/copy_file.c | |
parent | 43ca13714b4dc720a617ce23f89eb860bfb62303 (diff) |
Fix user permissions of copied directories.
Diffstat (limited to 'libbb/copy_file.c')
-rw-r--r-- | libbb/copy_file.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/libbb/copy_file.c b/libbb/copy_file.c index b2750ccf8..2d18b6087 100644 --- a/libbb/copy_file.c +++ b/libbb/copy_file.c @@ -64,6 +64,7 @@ int copy_file(const char *source, const char *dest, int flags) if (S_ISDIR(source_stat.st_mode)) { DIR *dp; struct dirent *d; + mode_t saved_umask = 0; if (!(flags & FILEUTILS_RECUR)) { error_msg("%s: omitting directory", source); @@ -77,7 +78,7 @@ int copy_file(const char *source, const char *dest, int flags) return -1; } } else { - mode_t mode, saved_umask; + mode_t mode; saved_umask = umask(0); mode = source_stat.st_mode; @@ -122,6 +123,12 @@ int copy_file(const char *source, const char *dest, int flags) perror_msg("unable to close directory `%s'", source); status = -1; } + + if (!dest_exists && + chmod(dest, source_stat.st_mode & ~saved_umask) < 0) { + perror_msg("unable to change permissions of `%s'", dest); + status = -1; + } } else if (S_ISREG(source_stat.st_mode)) { FILE *sfp, *dfp; |