checksum: Stop reusing the same Core::File for multiple files

Since we were just repeatedly calling `->open()` on the same Core::File
no one was clearing it's internal buffer, which means hashing multiple
files in one go would result in different hashes than hashing each file
separately.
This commit is contained in:
Idan Horowitz 2021-09-21 19:18:19 +03:00
parent d792869799
commit e12a707ca1
Notes: sideshowbarker 2024-07-18 03:34:53 +09:00

View file

@ -48,21 +48,18 @@ int main(int argc, char** argv)
Crypto::Hash::Manager hash;
hash.initialize(hash_kind);
bool success;
auto has_error = false;
auto file = Core::File::construct();
for (auto const& path : paths) {
if (path == "-") {
success = file->open(STDIN_FILENO, Core::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescriptor::No);
} else {
file->set_filename(path);
success = file->open(Core::OpenMode::ReadOnly);
}
if (!success) {
warnln("{}: {}: {}", argv[0], path, file->error_string());
has_error = true;
continue;
NonnullRefPtr<Core::File> file = Core::File::standard_input();
if (path != "-"sv) {
auto file_or_error = Core::File::open(path, Core::OpenMode::ReadOnly);
if (file_or_error.is_error()) {
warnln("{}: {}: {}", argv[0], path, file->error_string());
has_error = true;
continue;
}
file = file_or_error.release_value();
}
while (!file->eof() && !file->has_error())