Browse Source

Fix fileExists, use openFailed

Scott Lahteine 4 years ago
parent
commit
ee4c2b36b8
1 changed files with 17 additions and 7 deletions
  1. 17
    7
      Marlin/src/sd/cardreader.cpp

+ 17
- 7
Marlin/src/sd/cardreader.cpp View File

662
 //
662
 //
663
 bool CardReader::fileExists(const char * const path) {
663
 bool CardReader::fileExists(const char * const path) {
664
   if (!isMounted()) return false;
664
   if (!isMounted()) return false;
665
+
666
+  DEBUG_ECHOLNPAIR("fileExists: ", path);
667
+
668
+  // Dive to the file's directory and get the base name
665
   SdFile *diveDir = nullptr;
669
   SdFile *diveDir = nullptr;
666
   const char * const fname = diveToFile(false, diveDir, path);
670
   const char * const fname = diveToFile(false, diveDir, path);
667
-  if (fname) {
668
-    diveDir->rewind();
669
-    selectByName(*diveDir, fname);
670
-    //diveDir->close();
671
-  }
672
-  return !!fname;
671
+  if (!fname) return false;
672
+
673
+  // Get the longname of the checked file
674
+  //diveDir->rewind();
675
+  //selectByName(*diveDir, fname);
676
+  //diveDir->close();
677
+
678
+  // Try to open the file and return the result
679
+  SdFile tmpFile;
680
+  const bool success = tmpFile.open(diveDir, fname, O_READ);
681
+  if (success) tmpFile.close();
682
+  return success;
673
 }
683
 }
674
 
684
 
675
 //
685
 //
1231
     if (!isMounted()) return;
1241
     if (!isMounted()) return;
1232
     if (recovery.file.isOpen()) return;
1242
     if (recovery.file.isOpen()) return;
1233
     if (!recovery.file.open(&root, recovery.filename, read ? O_READ : O_CREAT | O_WRITE | O_TRUNC | O_SYNC))
1243
     if (!recovery.file.open(&root, recovery.filename, read ? O_READ : O_CREAT | O_WRITE | O_TRUNC | O_SYNC))
1234
-      SERIAL_ECHOLNPAIR(STR_SD_OPEN_FILE_FAIL, recovery.filename, ".");
1244
+      openFailed(recovery.filename);
1235
     else if (!read)
1245
     else if (!read)
1236
       echo_write_to_file(recovery.filename);
1246
       echo_write_to_file(recovery.filename);
1237
   }
1247
   }

Loading…
Cancel
Save