Skip to content

Commit

Permalink
Fix fileExists, use openFailed
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored and tharts committed Jan 6, 2021
1 parent 22924b6 commit 1e18240
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions Marlin/src/sd/cardreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

//
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 1e18240

Please sign in to comment.