Merge remote-tracking branch

'origin/GP-1141_ghidra1_HiddenMergeFileCleanup' (Closes #1701)
This commit is contained in:
Ryan Kurtz
2022-07-12 01:21:18 -04:00
2 changed files with 49 additions and 4 deletions
@@ -590,6 +590,27 @@ public class IndexedLocalFileSystem extends LocalFileSystem {
indexJournal.open();
try {
String conflictedItemStorageName = findItemStorageName(parentPath, name);
String storageName = pfile.getStorageName();
if (conflictedItemStorageName != null) {
try {
if (storageName.compareTo(conflictedItemStorageName) <= 0) {
conflictedItemStorageName = storageName;
return true; // skip conflict orphan
}
// remove conflict orphan from index and, add newer item below
deallocateItemStorage(parentPath, name);
}
finally {
Msg.warn(this,
"Detected orphaned project file " + conflictedItemStorageName + ": " +
getPath(parentPath, name));
}
}
Folder folder = addFolderToIndexIfMissing(parentPath);
Item item = new Item(folder, name, pfile.getStorageName());
bumpNextFileIndexID(item.getStorageName());
@@ -753,6 +774,26 @@ public class IndexedLocalFileSystem extends LocalFileSystem {
return folder;
}
/**
* Find an existing storage location name
* @param folderPath
* @param itemName
* @return storage location name or null if one not defined within index
*/
private String findItemStorageName(String folderPath, String name) {
try {
Folder folder = getFolder(folderPath, GetFolderOption.READ_ONLY);
Item item = folder.items.get(name);
if (item != null) {
return item.itemStorage.storageName;
}
}
catch (NotFoundException e) {
// ignore
}
return null;
}
/**
* Find an existing storage location
* @param folderPath
@@ -1060,6 +1101,11 @@ public class IndexedLocalFileSystem extends LocalFileSystem {
newFolder = getFolder(newFolderPath, GetFolderOption.CREATE_ALL_NOTIFY);
}
LocalFolderItem conflictFolderItem = getItem(newFolderPath, newName);
if (conflictFolderItem != null) {
throw new DuplicateFileException("Item already exists: " + newName);
}
folderItem.moveTo(item.itemStorage.dir, item.itemStorage.storageName, newFolderPath,
newName);
@@ -218,10 +218,9 @@ public abstract class LocalFileSystem implements FileSystem {
if (item != null) {
item.deleteContent(null);
}
else {
// make sure we get item out of index
deallocateItemStorage(folderPath, itemName);
}
// make sure we get item out of index
deallocateItemStorage(folderPath, itemName);
}
String parentPath = folderPath + (folderPath.endsWith(SEPARATOR) ? "" : SEPARATOR);
for (String subfolder : getFolderNames(folderPath)) {