fix: fix VFS Delete op for Ramdisk driver
This commit is contained in:
+26
-10
@@ -374,25 +374,41 @@ namespace Fs::Ramdisk {
|
|||||||
|
|
||||||
int Delete(const char* path) {
|
int Delete(const char* path) {
|
||||||
if (path == nullptr) return -1;
|
if (path == nullptr) return -1;
|
||||||
if (path[0] == '/') path++;
|
|
||||||
|
int idx = FindEntryByPath(path);
|
||||||
|
if (idx < 0) return -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++) {
|
for (int i = 0; i < fileCount; i++) {
|
||||||
if (StrEqual(fileTable[i].name, path)) {
|
if (i == idx) continue;
|
||||||
// Free heap-allocated data
|
const char* name = fileTable[i].name;
|
||||||
if (fileTable[i].heapAllocated && fileTable[i].data) {
|
if (name[0] == '/') name++;
|
||||||
Memory::g_heap->Free(fileTable[i].data);
|
bool prefixMatch = true;
|
||||||
|
for (int k = 0; k <= normLen; k++) {
|
||||||
|
if (name[k] != normalized[k]) { prefixMatch = false; break; }
|
||||||
|
}
|
||||||
|
if (prefixMatch && name[normLen + 1] != '\0') return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shift remaining entries down
|
if (fileTable[idx].heapAllocated && fileTable[idx].data) {
|
||||||
for (int j = i; j < fileCount - 1; j++) {
|
Memory::g_heap->Free(fileTable[idx].data);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = idx; j < fileCount - 1; j++) {
|
||||||
fileTable[j] = fileTable[j + 1];
|
fileTable[j] = fileTable[j + 1];
|
||||||
}
|
}
|
||||||
fileCount--;
|
fileCount--;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return -1; // not found
|
|
||||||
}
|
|
||||||
|
|
||||||
int Mkdir(const char* path) {
|
int Mkdir(const char* path) {
|
||||||
if (path == nullptr) return -1;
|
if (path == nullptr) return -1;
|
||||||
|
|||||||
@@ -108,15 +108,16 @@ void filemanager_finish_rename(FileManagerState* fm) {
|
|||||||
filemanager_build_fullpath(new_path, 512,
|
filemanager_build_fullpath(new_path, 512,
|
||||||
fm->current_path, fm->rename_buf);
|
fm->current_path, fm->rename_buf);
|
||||||
|
|
||||||
|
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 (fm->is_dir[fm->rename_idx]) {
|
||||||
// Directory rename: copy recursively then delete old
|
|
||||||
if (filemanager_copy_dir_recursive(old_path, new_path))
|
if (filemanager_copy_dir_recursive(old_path, new_path))
|
||||||
filemanager_delete_recursive(old_path);
|
filemanager_delete_recursive(old_path);
|
||||||
} else {
|
} else {
|
||||||
// File rename: copy then delete old
|
|
||||||
if (filemanager_copy_file(old_path, new_path))
|
if (filemanager_copy_file(old_path, new_path))
|
||||||
montauk::fdelete(old_path);
|
montauk::fdelete(old_path);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
filemanager_read_dir(fm);
|
filemanager_read_dir(fm);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user