idrassi / DirHash

Windows command line utility to compute hash of directories and files
BSD 3-Clause "New" or "Revised" License
111 stars 11 forks source link

verify switch stop DirHash when a file is removed #5

Closed janemba closed 3 years ago

janemba commented 3 years ago

Hello,

I would like to use -verify switch but some files has been removed from the folder. In this case DirHash just stop. Is it possible to make DirHash continue and just warn if a file cannot be found ?

Thanks

idrassi commented 3 years ago

I can't reproduce this issue: when I use -verify switch to verify the checksum of folder against a checksum files, DirHash doesn't stop if a file is removed from the folder since it finds all remaining files in the checksum file.

Maybe you are referring to the case where an entry is removed from the checksum file or if a file was added to the folder. Is this the case?

Thank you for your clarification and possibly an example use case.

janemba commented 3 years ago

Hello,

The use case is simple. I did a recursive checksum and saved the checksum file. Then, weeks later I used -verify switch. But in the meantime some files has been removed from some folders. As a consequence, DirHash (with -verify switch) can't find those files. So, when I use DirHash with -verify switch I have a file not found error and then DirHash just stop.

The scenario is easy to reproduce. Just use DirHash in a folder and save the output. Remove some files in the folder and use DirHash with -verify switch.

Now, looking at source code of DirHash.cpp file I noticed in line 1892 the program stop if the file path cannot be found.

Thanks

idrassi commented 3 years ago

I did the same use case and if some files don't exist anymore then the verification succeeds because DirHash doesn't use the file paths from the checksum file but rather it hashes existing files and it compares their hash with corresponding value in checksum file. Moreover, the error at line 1892 is returned if the checksum file can't be parsed correctly or if its path is wrong. So, this is a different issue.

The only case where the verification would stop with a file not found error is if a file is removed in the middle of the verification operations. For example, you have a folder with 1000 files and you ask DirHash to verify this folder: DirHash starts by listing all files in the folder and then it iterates over all these files, so during the verification if a file in this folder is removed before being processed, DirHash will not be able to open it and it will stop with error.

I don't think this is your case. Or is it?

idrassi commented 3 years ago

The other case of error is if a file is added in the folder and it was not there before: DirHash will complain that it can't find the file in the checksum list and it will stop.

Maybe this is your real issue?

janemba commented 3 years ago

The only case where the verification would stop with a file not found error is if a file is removed in the middle of the >verification operations. For example, you have a folder with 1000 files and you ask DirHash to verify this folder: DirHash >starts by listing all files in the folder and then it iterates over all these files, so during the verification if a file in this folder is >removed before being processed, DirHash will not be able to open it and it will stop with error.

I don't think this is your case. Or is it?

No it's not my case.

The other case of error is if a file is added in the folder and it was not there before: DirHash will complain that it can't find the >file in the checksum list and it will stop.

Maybe this is your real issue?

It may be the case but I have to verify it to be sure and unfortunately, I cannot do it now. I will let you know after checking.

idrassi commented 3 years ago

I have implemented a switch -skipError that will make DirHash ignore non fatal errors. This should fix the issue you are encountering. I have published version 1.12 that includes this switch alongside other changes like the support of Blake3 and Blake2 hash algorithms.

I will close this issue. Please feel free to reopen if you still have the issue.