mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:27:35 +00:00
chown: Don't bail immediately on error
Previously, chown would exit immediately if there was an error changing file ownership. We now print an error to stderr and continue when an error occurs.
This commit is contained in:
parent
bee316cfbe
commit
907e0b9e1d
1 changed files with 23 additions and 12 deletions
|
@ -70,31 +70,42 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Function<ErrorOr<void>(StringView)> update_path_owner = [&](StringView path) -> ErrorOr<void> {
|
Function<bool(StringView)> update_path_owner = [&](StringView path) {
|
||||||
auto stat = TRY(Core::System::lstat(path));
|
auto stat_or_error = Core::System::lstat(path);
|
||||||
|
if (stat_or_error.is_error()) {
|
||||||
|
warnln("Could not stat '{}': {}", path, stat_or_error.release_error());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto stat = stat_or_error.release_value();
|
||||||
|
|
||||||
if (S_ISLNK(stat.st_mode) && !follow_symlinks && !paths.contains_slow(path))
|
if (S_ISLNK(stat.st_mode) && !follow_symlinks && !paths.contains_slow(path))
|
||||||
return {};
|
return false;
|
||||||
|
|
||||||
if (no_dereference) {
|
auto success = true;
|
||||||
TRY(Core::System::lchown(path, new_uid, new_gid));
|
auto maybe_error = no_dereference
|
||||||
} else {
|
? Core::System::lchown(path, new_uid, new_gid)
|
||||||
TRY(Core::System::chown(path, new_uid, new_gid));
|
: Core::System::chown(path, new_uid, new_gid);
|
||||||
|
|
||||||
|
if (maybe_error.is_error()) {
|
||||||
|
warnln("Failed to change owner of '{}': {}", path, maybe_error.release_error());
|
||||||
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recursive && S_ISDIR(stat.st_mode)) {
|
if (recursive && S_ISDIR(stat.st_mode)) {
|
||||||
Core::DirIterator it(path, Core::DirIterator::Flags::SkipParentAndBaseDir);
|
Core::DirIterator it(path, Core::DirIterator::Flags::SkipParentAndBaseDir);
|
||||||
|
|
||||||
while (it.has_next())
|
while (it.has_next())
|
||||||
TRY(update_path_owner(it.next_full_path()));
|
success &= update_path_owner(it.next_full_path());
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return success;
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto path : paths) {
|
auto success = true;
|
||||||
TRY(update_path_owner(path));
|
for (auto const& path : paths) {
|
||||||
|
success &= update_path_owner(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return success ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue