return true;
}
+bool CopyOwnershipAndPermissions(const boost::filesystem::path& src,
+ const boost::filesystem::path& dst) {
+ if(!bf::exists(src)) {
+ LOG(ERROR) << "Failed to copy ownership and permissions"
+ << " from " << src << " to " << dst;
+ return false;
+ }
+ bf::perms permissions = bf::status(src).permissions();
+ struct stat stats;
+ stat(src.c_str(), &stats);
+ if(!SetDirOwnershipAndPermissions(dst, permissions, stats.st_uid,
+ stats.st_gid)) {
+ LOG(ERROR) << "Failed to copy ownership and permissions"
+ << " from " << src << " to " << dst;
+ return false;
+ }
+ return true;
+}
+
bool CopyDir(const bf::path& src, const bf::path& dst,
FSFlag flags, bool skip_symlink) {
try {
LOG(ERROR) << "Unable to create destination directory" << dst;
return false;
}
+ if (flags & FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS)
+ CopyOwnershipAndPermissions(src, dst);
} else {
if (!(flags & (FS_MERGE_SKIP | FS_MERGE_OVERWRITE))) {
LOG(ERROR) << "Destination directory " << dst.string()
<< " already exists.";
return false;
}
+ if (flags & (FS_MERGE_OVERWRITE | FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS))
+ CopyOwnershipAndPermissions(src, dst);
}
} catch (const bf::filesystem_error& error) {
LOG(ERROR) << "Failed to copy directory: " << error.what();
else
bf::copy_file(current, destination);
+ if (flags & FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS)
+ CopyOwnershipAndPermissions(current, destination);
+
if (flags & FS_COMMIT_COPY_FILE) {
if (flags & FS_MERGE_OVERWRITE)
bf::remove(target);
FS_NONE = 0,
FS_MERGE_SKIP = (1 << 0),
FS_MERGE_OVERWRITE = (1 << 1),
- FS_COMMIT_COPY_FILE = (1 << 2)
+ FS_COMMIT_COPY_FILE = (1 << 2),
+ FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS = (1 << 3)
};
FSFlag operator|(FSFlag a, FSFlag b);
boost::filesystem::perms permissions, uid_t uid,
gid_t gid);
+bool CopyOwnershipAndPermissions(const boost::filesystem::path& src,
+ const boost::filesystem::path& dst);
+
int64_t GetUnpackedPackageSize(const boost::filesystem::path& path);
int64_t GetDirectorySize(const boost::filesystem::path& path);