Browse Source

[2.0.x] Fix SD wrong filename list (#9342)

If last file in directory has short filename and is preceded by a deleted long file name. SD menu will wrongly report long deleted file name as last entry
GMagician 6 years ago
parent
commit
6d4bc9a1f8
1 changed files with 9 additions and 5 deletions
  1. 9
    5
      Marlin/src/sd/SdBaseFile.cpp

+ 9
- 5
Marlin/src/sd/SdBaseFile.cpp View File

@@ -1054,8 +1054,9 @@ int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) {
1054 1054
   // if not a directory file or miss-positioned return an error
1055 1055
   if (!isDir() || (0x1F & curPosition_)) return -1;
1056 1056
 
1057
-  //If we have a longFilename buffer, mark it as invalid. If we find a long filename it will be filled automaticly.
1058
-  if (longFilename != NULL) longFilename[0] = '\0';
1057
+  // If we have a longFilename buffer, mark it as invalid.
1058
+  // If long filename is found it will be filled automatically.
1059
+  if (longFilename) longFilename[0] = '\0';
1059 1060
 
1060 1061
   while (1) {
1061 1062
 
@@ -1065,12 +1066,15 @@ int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) {
1065 1066
     // last entry if DIR_NAME_FREE
1066 1067
     if (dir->name[0] == DIR_NAME_FREE) return 0;
1067 1068
 
1068
-    // skip empty entries and entry for .  and ..
1069
-    if (dir->name[0] == DIR_NAME_DELETED || dir->name[0] == '.') continue;
1069
+    // skip deleted entry and entry for .  and ..
1070
+    if (dir->name[0] == DIR_NAME_DELETED || dir->name[0] == '.') {
1071
+      if (longFilename) longFilename[0] = '\0';     // Invalidate erased file long name, if any
1072
+      continue;
1073
+    }
1070 1074
 
1071 1075
     // Fill the long filename if we have a long filename entry.
1072 1076
     // Long filename entries are stored before the short filename.
1073
-    if (longFilename != NULL && DIR_IS_LONG_NAME(dir)) {
1077
+    if (longFilename && DIR_IS_LONG_NAME(dir)) {
1074 1078
       vfat_t* VFAT = (vfat_t*)dir;
1075 1079
       // Sanity-check the VFAT entry. The first cluster is always set to zero. And the sequence number should be higher than 0
1076 1080
       if (VFAT->firstClusterLow == 0) {

Loading…
Cancel
Save