mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:37:35 +00:00
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:
parent
d792869799
commit
e12a707ca1
1 changed files with 9 additions and 12 deletions
|
@ -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())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue