mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 17:25:06 +00:00
touch: Don't bail immediately on error
Previously, touch would exit immediately if there was an error changing file permissions. We now print an error to stderr and continue when an error occurs.
This commit is contained in:
parent
05bc98a410
commit
16fcbe555e
1 changed files with 19 additions and 7 deletions
|
@ -239,16 +239,28 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
if (update_mtime && !update_atime)
|
if (update_mtime && !update_atime)
|
||||||
atime.tv_nsec = UTIME_OMIT;
|
atime.tv_nsec = UTIME_OMIT;
|
||||||
|
|
||||||
|
auto has_errors = false;
|
||||||
for (auto path : paths) {
|
for (auto path : paths) {
|
||||||
if (FileSystem::exists(path)) {
|
if (FileSystem::exists(path)) {
|
||||||
if (utimensat(AT_FDCWD, path.characters(), times, 0) == -1)
|
if (utimensat(AT_FDCWD, path.characters(), times, 0) == -1) {
|
||||||
err("failed to touch '{}': {}", path, strerror(errno));
|
warnln("failed to touch '{}': {}", path, strerror(errno));
|
||||||
|
has_errors = true;
|
||||||
|
}
|
||||||
} else if (!no_create_file) {
|
} else if (!no_create_file) {
|
||||||
int fd = TRY(Core::System::open(path, O_CREAT, 0100644));
|
auto error_or_fd = Core::System::open(path, O_CREAT, 0100644);
|
||||||
if (futimens(fd, times) == -1)
|
if (error_or_fd.is_error()) {
|
||||||
err("failed to touch '{}': {}", path, strerror(errno));
|
warnln("failed to open '{}': {}", path, strerror(error_or_fd.error().code()));
|
||||||
TRY(Core::System::close(fd));
|
has_errors = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (futimens(error_or_fd.value(), times) == -1) {
|
||||||
|
warnln("failed to touch '{}': {}", path, strerror(errno));
|
||||||
|
has_errors = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
(void)Core::System::close(error_or_fd.value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return has_errors ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue