synchronized final F addLink ( String path ) throws IOException { if ( ++ linksTraversed > MAXSYMLINKS ) { throw new IllegalArgumentException ( "Too many links to follow (> " + MAXSYMLINKS + ")." ) ; } F resolvedPath = _resolvedPaths . get ( path ) ; if ( resolvedPath == null ) { for ( String unresolvedPath : _unresolvedPaths ) { if ( path . equals ( unresolvedPath ) || path . startsWith ( unresolvedPath + "/" ) ) { throw new IOException ( "Links form a loop: " + path ) ; } } _unresolvedPaths . add ( path ) ; } return resolvedPath ; }
Checks for problems . If the link has already been resolved it returns the final file . If not it adds the link path to the list of unresolved paths that have been seen while evaluating this chain .