From deb63b6e7690c8220eba89da826591450d76c6b9 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Mon, 22 Jan 2024 07:57:47 +1100 Subject: [PATCH] Update util.d Fix readLocalFile for zero byte files --- src/util.d | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/util.d b/src/util.d index d981dc61..629b1d5a 100644 --- a/src/util.d +++ b/src/util.d @@ -275,24 +275,28 @@ bool retryInternetConnectivtyTest(ApplicationConfig appConfig) { // https://github.com/abraunegg/onedrive/issues/113 // returns true if file can be accessed bool readLocalFile(string path) { - try { - // Attempt to read up to the first 1 byte of the file - auto data = read(path, 1); + // What is the file size + if (getSize(path) != 0) { + try { + // Attempt to read up to the first 1 byte of the file + auto data = read(path, 1); - // Check if the read operation was successful - if (data.length != 1) { - // What is the file size? - if (getSize(path) != 0) { + // Check if the read operation was successful + if (data.length != 1) { + // Read operation not sucessful addLogEntry("Failed to read the required amount from the file: " ~ path); + return false; } - return false; - } - } catch (std.file.FileException e) { - // Unable to read the file, log the error message - displayFileSystemErrorMessage(e.msg, getFunctionName!({})); - return false; - } - return true; + } catch (std.file.FileException e) { + // Unable to read the file, log the error message + displayFileSystemErrorMessage(e.msg, getFunctionName!({})); + return false; + } + return true; + } else { + // zero byte files cannot be read, return true + return true; + } } // Calls globMatch for each string in pattern separated by '|'