Fix fileExists, use openFailed

This commit is contained in:
Scott Lahteine 2020-12-07 04:36:22 -06:00
parent 00143f77d0
commit ee4c2b36b8

View File

@ -662,14 +662,24 @@ void CardReader::openFileWrite(char * const path) {
// //
bool CardReader::fileExists(const char * const path) { bool CardReader::fileExists(const char * const path) {
if (!isMounted()) return false; if (!isMounted()) return false;
DEBUG_ECHOLNPAIR("fileExists: ", path);
// Dive to the file's directory and get the base name
SdFile *diveDir = nullptr; SdFile *diveDir = nullptr;
const char * const fname = diveToFile(false, diveDir, path); const char * const fname = diveToFile(false, diveDir, path);
if (fname) { if (!fname) return false;
diveDir->rewind();
selectByName(*diveDir, fname); // Get the longname of the checked file
//diveDir->rewind();
//selectByName(*diveDir, fname);
//diveDir->close(); //diveDir->close();
}
return !!fname; // 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 (!isMounted()) return;
if (recovery.file.isOpen()) return; if (recovery.file.isOpen()) return;
if (!recovery.file.open(&root, recovery.filename, read ? O_READ : O_CREAT | O_WRITE | O_TRUNC | O_SYNC)) 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) else if (!read)
echo_write_to_file(recovery.filename); echo_write_to_file(recovery.filename);
} }