fix: fix VFS Delete op for Ramdisk driver

This commit is contained in:
2026-05-27 18:06:27 +02:00
parent 190b0f9364
commit 90788e842f
2 changed files with 38 additions and 21 deletions
+29 -13
View File
@@ -374,24 +374,40 @@ namespace Fs::Ramdisk {
int Delete(const char* path) {
if (path == nullptr) return -1;
if (path[0] == '/') path++;
for (int i = 0; i < fileCount; i++) {
if (StrEqual(fileTable[i].name, path)) {
// Free heap-allocated data
if (fileTable[i].heapAllocated && fileTable[i].data) {
Memory::g_heap->Free(fileTable[i].data);
}
int idx = FindEntryByPath(path);
if (idx < 0) return -1;
// Shift remaining entries down
for (int j = i; j < fileCount - 1; j++) {
fileTable[j] = fileTable[j + 1];
// For directories, refuse if any other entry lives under this prefix.
if (fileTable[idx].isDirectory) {
char normalized[MaxNameLen];
int normLen = NormalizePath(path, normalized, MaxNameLen);
if (normLen < 0) return -1;
if (normLen + 1 >= MaxNameLen) return -1;
normalized[normLen] = '/';
normalized[normLen + 1] = '\0';
for (int i = 0; i < fileCount; i++) {
if (i == idx) continue;
const char* name = fileTable[i].name;
if (name[0] == '/') name++;
bool prefixMatch = true;
for (int k = 0; k <= normLen; k++) {
if (name[k] != normalized[k]) { prefixMatch = false; break; }
}
fileCount--;
return 0;
if (prefixMatch && name[normLen + 1] != '\0') return -1;
}
}
return -1; // not found
if (fileTable[idx].heapAllocated && fileTable[idx].data) {
Memory::g_heap->Free(fileTable[idx].data);
}
for (int j = idx; j < fileCount - 1; j++) {
fileTable[j] = fileTable[j + 1];
}
fileCount--;
return 0;
}
int Mkdir(const char* path) {
@@ -108,14 +108,15 @@ void filemanager_finish_rename(FileManagerState* fm) {
filemanager_build_fullpath(new_path, 512,
fm->current_path, fm->rename_buf);
if (fm->is_dir[fm->rename_idx]) {
// Directory rename: copy recursively then delete old
if (filemanager_copy_dir_recursive(old_path, new_path))
filemanager_delete_recursive(old_path);
} else {
// File rename: copy then delete old
if (filemanager_copy_file(old_path, new_path))
montauk::fdelete(old_path);
if (montauk::frename(old_path, new_path) != 0) {
// Fall back to copy + delete for drivers that don't support rename
if (fm->is_dir[fm->rename_idx]) {
if (filemanager_copy_dir_recursive(old_path, new_path))
filemanager_delete_recursive(old_path);
} else {
if (filemanager_copy_file(old_path, new_path))
montauk::fdelete(old_path);
}
}
filemanager_read_dir(fm);