From 450e0aba27a831314286ffff724021b74e0173f2 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 6 Oct 2021 02:16:57 +0200 Subject: [PATCH] fix more bugs --- src/FATStorage.cpp | 22 +++++++++++++++++----- src/FATStorage.h | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/FATStorage.cpp b/src/FATStorage.cpp index b19fa37b..1f91c0a6 100644 --- a/src/FATStorage.cpp +++ b/src/FATStorage.cpp @@ -611,14 +611,14 @@ bool FATStorage::DeleteDirectory(std::string path, int level) return true; } -void FATStorage::CleanupDirectory(std::string path, int level) +void FATStorage::CleanupDirectory(std::string sourcedir, std::string path, int level) { if (level >= 32) return; fDIR dir; FILINFO info; FRESULT res; - +printf("CLEANING UP DIRECTORY %s (level=%d)\n", path.c_str(), level); std::string fullpath = "0:/" + path; res = f_opendir(&dir, fullpath.c_str()); if (res != FR_OK) return; @@ -634,11 +634,18 @@ void FATStorage::CleanupDirectory(std::string path, int level) if (!info.fname[0]) break; std::string fullpath = path + info.fname; - +printf("FOUND ENTRY %s %08X (%d/%d, %d)\n", + fullpath.c_str(), info.fattrib, FileIndex.count(fullpath), DirIndex.count(fullpath), + fs::exists(sourcedir+"/"+fullpath)); if (info.fattrib & AM_DIR) { if (DirIndex.count(fullpath) < 1) dirdeletelist.push_back(fullpath); + else if (!fs::is_directory(sourcedir+"/"+fullpath)) + { + DirIndex.erase(fullpath); + dirdeletelist.push_back(fullpath); + } else subdirlist.push_back(fullpath); } @@ -646,6 +653,11 @@ void FATStorage::CleanupDirectory(std::string path, int level) { if (FileIndex.count(fullpath) < 1) filedeletelist.push_back(fullpath); + else if (!fs::is_regular_file(sourcedir+"/"+fullpath)) + { + FileIndex.erase(fullpath); + filedeletelist.push_back(fullpath); + } } } @@ -665,7 +677,7 @@ void FATStorage::CleanupDirectory(std::string path, int level) for (auto& entry : subdirlist) { - CleanupDirectory(entry+"/", level+1); + CleanupDirectory(sourcedir, entry+"/", level+1); } } @@ -727,7 +739,7 @@ bool FATStorage::BuildSubdirectory(const char* sourcedir, const char* path, int if (level == 0) { // remove whatever isn't in the index - CleanupDirectory("", 0); + CleanupDirectory(sourcedir, "", 0); int srclen = strlen(sourcedir); diff --git a/src/FATStorage.h b/src/FATStorage.h index 92e5c7df..4d664376 100644 --- a/src/FATStorage.h +++ b/src/FATStorage.h @@ -56,7 +56,7 @@ private: bool CanFitFile(u32 len); bool DeleteDirectory(std::string path, int level); - void CleanupDirectory(std::string path, int level); + void CleanupDirectory(std::string sourcedir, std::string path, int level); bool ImportFile(std::string path, std::string in); bool BuildSubdirectory(const char* sourcedir, const char* path, int level);