aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Fernando J. Pereda <ferdy@ferdyx.org> 2008-01-11 14:17:03 +0000
committerAvatar Fernando J. Pereda <ferdy@ferdyx.org> 2008-01-11 14:17:03 +0000
commita1c03a3625cbf0265a70404821999b3cbf11eea2 (patch)
tree6f3dd4a33921ca7beba741db72ed6d8318b41f7c
parenta8280639c004deef84a1809ddf9c037dafe71405 (diff)
downloadpaludis-a1c03a3625cbf0265a70404821999b3cbf11eea2.tar.gz
paludis-a1c03a3625cbf0265a70404821999b3cbf11eea2.tar.xz
Do owner/group fixing for the rename case too.
-rw-r--r--paludis/merger.cc33
1 files changed, 23 insertions, 10 deletions
diff --git a/paludis/merger.cc b/paludis/merger.cc
index 8b19119..b042c43 100644
--- a/paludis/merger.cc
+++ b/paludis/merger.cc
@@ -634,6 +634,14 @@ Merger::install_file(const FSEntry & src, const FSEntry & dst_dir, const std::st
throw MergerError("Could not set SELinux context on '"
+ stringify(src) + "': " + stringify(::strerror(errno)));
+ if (! _options.no_chown)
+ {
+ uid_t new_uid(src.owner() == _options.environment->reduced_uid() ? 0 : -1);
+ gid_t new_gid(src.group() == _options.environment->reduced_gid() ? 0 : -1);
+ if (0 == new_uid || 0 == new_gid)
+ FSEntry(src).chown(new_uid, new_gid);
+ }
+
if (0 == ::rename(stringify(src).c_str(), stringify(dst_real).c_str()))
{
if (! dst_real.utime())
@@ -653,12 +661,6 @@ Merger::install_file(const FSEntry & src, const FSEntry & dst_dir, const std::st
if (-1 == output_fd)
throw MergerError("Cannot write '" + stringify(dst) + "': " + stringify(::strerror(errno)));
- if (! _options.no_chown)
- if (0 != ::fchown(output_fd,
- src.owner() == _options.environment->reduced_uid() ? 0 : src.owner(),
- src.group() == _options.environment->reduced_gid() ? 0 : src.group()))
- throw MergerError("Cannot fchown '" + stringify(dst) + "': " + stringify(::strerror(errno)));
-
/* set*id bits */
if (0 != ::fchmod(output_fd, src.permissions()))
throw MergerError("Cannot fchmod '" + stringify(dst) + "': " + stringify(::strerror(errno)));
@@ -719,6 +721,13 @@ Merger::record_renamed_dir_recursive(const FSEntry & dst)
record_install_dir(dst, dst.dirname());
for (DirIterator d(dst, false), d_end ; d != d_end ; ++d)
{
+ if (! _options.no_chown)
+ {
+ uid_t new_uid(d->owner() == _options.environment->reduced_uid() ? 0 : -1);
+ gid_t new_gid(d->group() == _options.environment->reduced_gid() ? 0 : -1);
+ if (0 == new_uid || 0 == new_gid)
+ FSEntry(*d).chown(new_uid, new_gid);
+ }
EntryType m(entry_type(*d));
switch (m)
{
@@ -784,6 +793,14 @@ Merger::install_dir(const FSEntry & src, const FSEntry & dst_dir)
throw MergerError("Could not set SELinux context on '"
+ stringify(src) + "': " + stringify(::strerror(errno)));
+ if (! _options.no_chown)
+ {
+ uid_t new_uid(src.owner() == _options.environment->reduced_uid() ? 0 : -1);
+ gid_t new_gid(src.group() == _options.environment->reduced_gid() ? 0 : -1);
+ if (0 == new_uid || 0 == new_gid)
+ FSEntry(src).chown(new_uid, new_gid);
+ }
+
if (is_selinux_enabled())
relabel_dir_recursive(src, dst);
@@ -796,10 +813,6 @@ Merger::install_dir(const FSEntry & src, const FSEntry & dst_dir)
{
Log::get_instance()->message(ll_debug, lc_context, "rename failed. Falling back to recursive copy.");
dst.mkdir(mode);
- if (! _options.no_chown)
- dst.chown(
- src.owner() == _options.environment->reduced_uid() ? 0 : src.owner(),
- src.group() == _options.environment->reduced_gid() ? 0 : src.group());
/* pick up set*id bits */
dst.chmod(src.permissions());
}