mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 09:17:45 +00:00
LibCore+Everywhere: Return an Error from DirIterator::error()
This also removes DirIterator::error_string(), since the same strerror() string will be included when you print the Error itself. Except in `ls` which is still using fprintf() for now.
This commit is contained in:
parent
a98ae8f357
commit
774f328783
17 changed files with 44 additions and 46 deletions
|
@ -142,8 +142,9 @@ ErrorOr<u64> print_space_usage(DeprecatedString const& path, DuOption const& du_
|
|||
if (is_directory) {
|
||||
auto di = Core::DirIterator(path, Core::DirIterator::SkipParentAndBaseDir);
|
||||
if (di.has_error()) {
|
||||
outln("du: cannot read directory '{}': {}", path, di.error_string());
|
||||
return Error::from_string_literal("An error occurred. See previous error.");
|
||||
auto error = di.error();
|
||||
outln("du: cannot read directory '{}': {}", path, error);
|
||||
return error;
|
||||
}
|
||||
|
||||
while (di.has_next()) {
|
||||
|
|
|
@ -170,7 +170,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
if (di.has_error()) {
|
||||
status = 1;
|
||||
fprintf(stderr, "%s: %s\n", path.characters(), di.error_string());
|
||||
fprintf(stderr, "%s: %s\n", path.characters(), strerror(di.error().code()));
|
||||
}
|
||||
|
||||
while (di.has_next()) {
|
||||
|
@ -396,7 +396,8 @@ static int do_file_system_object_long(char const* path)
|
|||
Core::DirIterator di(path, flags);
|
||||
|
||||
if (di.has_error()) {
|
||||
if (di.error() == ENOTDIR) {
|
||||
auto error = di.error();
|
||||
if (error.code() == ENOTDIR) {
|
||||
struct stat stat {
|
||||
};
|
||||
int rc = lstat(path, &stat);
|
||||
|
@ -406,7 +407,7 @@ static int do_file_system_object_long(char const* path)
|
|||
return 0;
|
||||
return 2;
|
||||
}
|
||||
fprintf(stderr, "%s: %s\n", path, di.error_string());
|
||||
fprintf(stderr, "%s: %s\n", path, strerror(di.error().code()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -510,7 +511,8 @@ int do_file_system_object_short(char const* path)
|
|||
|
||||
Core::DirIterator di(path, flags);
|
||||
if (di.has_error()) {
|
||||
if (di.error() == ENOTDIR) {
|
||||
auto error = di.error();
|
||||
if (error.code() == ENOTDIR) {
|
||||
size_t nprinted = 0;
|
||||
bool status = print_filesystem_object_short(path, path, &nprinted);
|
||||
printf("\n");
|
||||
|
@ -518,7 +520,7 @@ int do_file_system_object_short(char const* path)
|
|||
return 0;
|
||||
return 2;
|
||||
}
|
||||
fprintf(stderr, "%s: %s\n", path, di.error_string());
|
||||
fprintf(stderr, "%s: %s\n", path, strerror(di.error().code()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,8 +27,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
Core::DirIterator di("/sys/devices/storage/", Core::DirIterator::SkipParentAndBaseDir);
|
||||
if (di.has_error()) {
|
||||
warnln("Failed to open /sys/devices/storage - {}", di.error());
|
||||
return 1;
|
||||
auto error = di.error();
|
||||
warnln("Failed to open /sys/devices/storage - {}", error);
|
||||
return error;
|
||||
}
|
||||
|
||||
outln(format_row, "LUN"sv, "Command set"sv, "Block Size"sv, "Last LBA"sv);
|
||||
|
|
|
@ -70,8 +70,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
Core::DirIterator di("/sys/bus/pci/", Core::DirIterator::SkipParentAndBaseDir);
|
||||
if (di.has_error()) {
|
||||
warnln("Failed to open /sys/bus/pci - {}", di.error());
|
||||
return 1;
|
||||
auto error = di.error();
|
||||
warnln("Failed to open /sys/bus/pci - {}", error);
|
||||
return error;
|
||||
}
|
||||
|
||||
TRY(Core::System::pledge("stdio rpath"));
|
||||
|
|
|
@ -129,8 +129,8 @@ static ErrorOr<void> mount_all()
|
|||
|
||||
auto fstab_directory_iterator = Core::DirIterator("/etc/fstab.d", Core::DirIterator::SkipDots);
|
||||
|
||||
if (fstab_directory_iterator.has_error() && fstab_directory_iterator.error() != ENOENT) {
|
||||
dbgln("Failed to open /etc/fstab.d: {}", fstab_directory_iterator.error_string());
|
||||
if (fstab_directory_iterator.has_error() && fstab_directory_iterator.error().code() != ENOENT) {
|
||||
dbgln("Failed to open /etc/fstab.d: {}", fstab_directory_iterator.error());
|
||||
} else if (!fstab_directory_iterator.has_error()) {
|
||||
while (fstab_directory_iterator.has_next()) {
|
||||
auto path = fstab_directory_iterator.next_full_path();
|
||||
|
|
|
@ -82,7 +82,7 @@ static int handle_show_all()
|
|||
{
|
||||
Core::DirIterator di("/sys/kernel/variables", Core::DirIterator::SkipDots);
|
||||
if (di.has_error()) {
|
||||
outln("DirIterator: {}", di.error_string());
|
||||
outln("DirIterator: {}", di.error());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ static void print_directory_tree(DeprecatedString const& root_path, int depth, D
|
|||
|
||||
Core::DirIterator di(root_path, flag_show_hidden_files ? Core::DirIterator::SkipParentAndBaseDir : Core::DirIterator::SkipDots);
|
||||
if (di.has_error()) {
|
||||
warnln("{}: {}", root_path, di.error_string());
|
||||
warnln("{}: {}", root_path, di.error());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ static void print_directory_tree(DeprecatedString const& root_path, int depth, D
|
|||
while (di.has_next()) {
|
||||
DeprecatedString name = di.next_path();
|
||||
if (di.has_error()) {
|
||||
warnln("{}: {}", root_path, di.error_string());
|
||||
warnln("{}: {}", root_path, di.error());
|
||||
continue;
|
||||
}
|
||||
names.append(name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue