mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 17:40:27 +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
Notes:
sideshowbarker
2024-07-18 03:34:53 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/e12a707ca1a Pull-request: https://github.com/SerenityOS/serenity/pull/10168 Reviewed-by: https://github.com/awesomekling ✅
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…
Reference in a new issue