From ee4c2b36b8f06ac032cfcac84ca252fa114b61b2 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 7 Dec 2020 04:36:22 -0600 Subject: [PATCH] Fix fileExists, use openFailed --- Marlin/src/sd/cardreader.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index bce84bbd39..7ba9f3d3d6 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -662,14 +662,24 @@ void CardReader::openFileWrite(char * const path) { // bool CardReader::fileExists(const char * const path) { if (!isMounted()) return false; + + DEBUG_ECHOLNPAIR("fileExists: ", path); + + // Dive to the file's directory and get the base name SdFile *diveDir = nullptr; const char * const fname = diveToFile(false, diveDir, path); - if (fname) { - diveDir->rewind(); - selectByName(*diveDir, fname); - //diveDir->close(); - } - return !!fname; + if (!fname) return false; + + // Get the longname of the checked file + //diveDir->rewind(); + //selectByName(*diveDir, fname); + //diveDir->close(); + + // Try to open the file and return the result + SdFile tmpFile; + const bool success = tmpFile.open(diveDir, fname, O_READ); + if (success) tmpFile.close(); + return success; } // @@ -1231,7 +1241,7 @@ void CardReader::fileHasFinished() { if (!isMounted()) return; if (recovery.file.isOpen()) return; if (!recovery.file.open(&root, recovery.filename, read ? O_READ : O_CREAT | O_WRITE | O_TRUNC | O_SYNC)) - SERIAL_ECHOLNPAIR(STR_SD_OPEN_FILE_FAIL, recovery.filename, "."); + openFailed(recovery.filename); else if (!read) echo_write_to_file(recovery.filename); }