in commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/VirtualFileSystem.java [82:122]
public void addJunction(final String junctionPoint, final FileObject targetFile) throws FileSystemException {
final FileName junctionName = getFileSystemManager().resolveName(getRootName(), junctionPoint);
// Check for nested junction - these are not supported yet
if (getJunctionForFile(junctionName) != null) {
throw new FileSystemException("vfs.impl/nested-junction.error", junctionName);
}
try {
// Add to junction table
junctions.put(junctionName, targetFile);
// Attach to file
final DelegateFileObject junctionFile = (DelegateFileObject) getFileFromCache(junctionName);
if (junctionFile != null) {
junctionFile.setFile(targetFile);
}
// Create ancestors of junction point
FileName childName = junctionName;
boolean done = false;
for (AbstractFileName parentName = (AbstractFileName) childName.getParent(); !done
&& parentName != null; childName = parentName, parentName = (AbstractFileName) parentName
.getParent()) {
DelegateFileObject file = (DelegateFileObject) getFileFromCache(parentName);
if (file == null) {
file = new DelegateFileObject(parentName, this, null);
putFileToCache(file);
} else {
done = file.exists();
}
// As this is the parent of our junction it has to be a folder
file.attachChild(childName, FileType.FOLDER);
}
// TODO - attach all cached children of the junction point to their real file
} catch (final Exception e) {
throw new FileSystemException("vfs.impl/create-junction.error", junctionName, e);
}
}