}
bool SetOwnership(const bf::path& path, uid_t uid, gid_t gid) {
- int fd = open(path.c_str(), O_RDONLY);
- if (fd < 0) {
- LOG(ERROR) << "Can't open directory : " << path;
- return false;
- }
- int ret = fchown(fd, uid, gid);
- close(fd);
+ int ret = lchown(path.c_str(), uid, gid);
if (ret != 0) {
LOG(ERROR) << "Failed to change owner of: " << path;
return false;
iter != bf::recursive_directory_iterator();
++iter) {
bf::path current(iter->path());
- if (bf::is_symlink(symlink_status(current)))
- continue;
if (!SetOwnership(current, uid, gid))
return false;
}