if (target
&& (!FileSystemUtil.isFilesystemCaseSensitive() || renameConfig
.isSearchSimiliarDirectoriesEnabled())) {
searchPath = searchPath.toUpperCase();
}
DirectoryDescriptor result = (DirectoryDescriptor) path2file
.get(searchPath);
if (result != null) {
/*
* If the current directory is not marked as target, but now is
* requested as a target, it must be set as one.
*/
if (target && !result.isTargetDirectory()) {
result.setTargetDirectory(true);
/*
* This will result in a upward recursion, marking all parent
* directories as used for target. Stop if no parent file exist.
*/
DirectoryDescriptor current = result.getParent();
while (current != null) {
current.setTargetDirectory(true);
current = current.getParent();
}
}
// same with source
if (!target && !result.isSourceDirectory()) {
result.setSourceDirectory(true);
DirectoryDescriptor current = result.getParent();
while (current != null) {
current.setSourceDirectory(true);
current = current.getParent();
}
}
return result;
}
// From here on, the directory does not exist (In memory).
File directoryInstance = null;
if (target)
directoryInstance = getDirectoryFile(path);
else
directoryInstance = new File(path);
// assert parent directory first.
// Does a parent exist?
if (directoryInstance.getParentFile() != null) {
DirectoryDescriptor parent = assertDirectory(directoryInstance
.getParent(), target);
result = new DirectoryDescriptor(directoryInstance.getName(),
parent, !target, target);
parent.addChild(result);
} else {
// consider, for whatever reason the getName() for a drive (C:\)
// returns an empty string.
String rootName = directoryInstance.getAbsolutePath();
if (rootName.endsWith(File.separator)) {
rootName = rootName.substring(0, rootName.length() - 1);
}
result = new DirectoryDescriptor(rootName, null, !target, target);
// No, so it is a filesystem root (eg. c:\ or /)
if (!filesysroots.containsKey(rootName)) {
filesysroots.put(rootName, result);
}
}