Просмотр исходного кода

Fix fileExists, use openFailed

Scott Lahteine 4 лет назад
Родитель
Сommit
ee4c2b36b8
1 измененных файлов: 17 добавлений и 7 удалений
  1. 17
    7
      Marlin/src/sd/cardreader.cpp

+ 17
- 7
Marlin/src/sd/cardreader.cpp Просмотреть файл

@@ -662,14 +662,24 @@ void CardReader::openFileWrite(char * const path) {
662 662
 //
663 663
 bool CardReader::fileExists(const char * const path) {
664 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 669
   SdFile *diveDir = nullptr;
666 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,7 +1241,7 @@ void CardReader::fileHasFinished() {
1231 1241
     if (!isMounted()) return;
1232 1242
     if (recovery.file.isOpen()) return;
1233 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 1245
     else if (!read)
1236 1246
       echo_write_to_file(recovery.filename);
1237 1247
   }

Загрузка…
Отмена
Сохранить