1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:38:11 +00:00

file: Output directory when path is a directory

Before file would output 'text/html' when the path was a directory.
This commit is contained in:
Arjan Zuidema 2021-05-27 13:19:13 +02:00 committed by Linus Groh
parent e17a5dc2b9
commit c7bc1f59d8

View file

@ -120,12 +120,17 @@ int main(int argc, char** argv)
all_ok = false; all_ok = false;
continue; continue;
} }
// Read accounts for longest possible offset + signature we currently match against.
auto bytes = file->read(0x9006); if (file->is_directory()) {
auto file_name_guess = Core::guess_mime_type_based_on_filename(path); outln("{}: directory", path);
auto mime_type = Core::guess_mime_type_based_on_sniffed_bytes(bytes.bytes()).value_or(file_name_guess); } else {
auto human_readable_description = get_description_from_mime_type(mime_type, String(path)).value_or(mime_type); // Read accounts for longest possible offset + signature we currently match against.
outln("{}: {}", path, flag_mime_only ? mime_type : human_readable_description); auto bytes = file->read(0x9006);
auto file_name_guess = Core::guess_mime_type_based_on_filename(path);
auto mime_type = Core::guess_mime_type_based_on_sniffed_bytes(bytes.bytes()).value_or(file_name_guess);
auto human_readable_description = get_description_from_mime_type(mime_type, String(path)).value_or(mime_type);
outln("{}: {}", path, flag_mime_only ? mime_type : human_readable_description);
}
} }
return all_ok ? 0 : 1; return all_ok ? 0 : 1;