summaryrefslogtreecommitdiff
path: root/Userland/Utilities/file.cpp
diff options
context:
space:
mode:
authorArjan Zuidema <arjan@myalbum.com>2021-05-27 13:19:13 +0200
committerLinus Groh <mail@linusgroh.de>2021-05-27 13:18:23 +0100
commitc7bc1f59d8bbe165b99ac00ef2e9fda76e5095d7 (patch)
treee2da03049c8beb8ea3014be422dff9de65b17894 /Userland/Utilities/file.cpp
parente17a5dc2b93d9127a2d388345e79a0ccbae7f85f (diff)
downloadserenity-c7bc1f59d8bbe165b99ac00ef2e9fda76e5095d7.zip
file: Output directory when path is a directory
Before file would output 'text/html' when the path was a directory.
Diffstat (limited to 'Userland/Utilities/file.cpp')
-rw-r--r--Userland/Utilities/file.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/Userland/Utilities/file.cpp b/Userland/Utilities/file.cpp
index edfd9f14e8..e9e2414db7 100644
--- a/Userland/Utilities/file.cpp
+++ b/Userland/Utilities/file.cpp
@@ -120,12 +120,17 @@ int main(int argc, char** argv)
all_ok = false;
continue;
}
- // Read accounts for longest possible offset + signature we currently match against.
- 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);
+
+ if (file->is_directory()) {
+ outln("{}: directory", path);
+ } else {
+ // Read accounts for longest possible offset + signature we currently match against.
+ 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;