mirror of
https://github.com/abraunegg/onedrive
synced 2026-03-14 14:35:46 +01:00
* Despite code validation and the file just being written to disk, and the check passing that the file exists, handle that we now cannot open the file that was just created and wrote data to. Catch any error when attempting to open file to generate the file hash
This commit is contained in:
parent
025c756c0c
commit
d29a737f3f
1 changed files with 27 additions and 3 deletions
30
src/util.d
30
src/util.d
|
|
@ -136,7 +136,15 @@ void safeRemove(const(char)[] path) {
|
|||
// Returns the SHA1 hash hex string of a file
|
||||
string computeSha1Hash(string path) {
|
||||
SHA1 sha;
|
||||
auto file = File(path, "rb");
|
||||
File file;
|
||||
|
||||
try {
|
||||
file = File(path, "rb");
|
||||
} catch (ErrnoException e) {
|
||||
// log that we could not generate a hash
|
||||
addLogEntry("Failed to open file to compute SHA1 Hash: " ~ path ~ " - " ~ e.msg);
|
||||
}
|
||||
|
||||
scope(exit) file.close(); // Ensure file is closed post read
|
||||
foreach (ubyte[] data; chunks(file, 4096)) {
|
||||
sha.put(data);
|
||||
|
|
@ -150,7 +158,15 @@ string computeSha1Hash(string path) {
|
|||
// Returns the quickXorHash base64 string of a file
|
||||
string computeQuickXorHash(string path) {
|
||||
QuickXor qxor;
|
||||
auto file = File(path, "rb");
|
||||
File file;
|
||||
|
||||
try {
|
||||
file = File(path, "rb");
|
||||
} catch (ErrnoException e) {
|
||||
// log that we could not generate a hash
|
||||
addLogEntry("Failed to open file to compute QuickXor Hash: " ~ path ~ " - " ~ e.msg);
|
||||
}
|
||||
|
||||
scope(exit) file.close(); // Ensure file is closed post read
|
||||
foreach (ubyte[] data; chunks(file, 4096)) {
|
||||
qxor.put(data);
|
||||
|
|
@ -164,7 +180,15 @@ string computeQuickXorHash(string path) {
|
|||
// Returns the SHA256 hex string of a file
|
||||
string computeSHA256Hash(string path) {
|
||||
SHA256 sha256;
|
||||
auto file = File(path, "rb");
|
||||
File file;
|
||||
|
||||
try {
|
||||
file = File(path, "rb");
|
||||
} catch (ErrnoException e) {
|
||||
// log that we could not generate a hash
|
||||
addLogEntry("Failed to open file to compute SHA256 Hash: " ~ path ~ " - " ~ e.msg);
|
||||
}
|
||||
|
||||
scope(exit) file.close(); // Ensure file is closed post read
|
||||
foreach (ubyte[] data; chunks(file, 4096)) {
|
||||
sha256.put(data);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue