Class FileTree


  • final class FileTree
    extends java.lang.Object
    The tree of directories and files for the file system. Contains the file system root directories and provides the ability to look up files by path. One piece of the file store implementation.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static com.google.common.collect.ImmutableList<Name> EMPTY_PATH_NAMES  
      private static int MAX_SYMBOLIC_LINK_DEPTH
      Doesn't much matter, but this number comes from MIN_ELOOP_THRESHOLD here
      private com.google.common.collect.ImmutableSortedMap<Name,​Directory> roots
      Map of root names to root directories.
    • Constructor Summary

      Constructors 
      Constructor Description
      FileTree​(java.util.Map<Name,​Directory> roots)
      Creates a new file tree with the given root directories.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private @Nullable DirectoryEntry followSymbolicLink​(File dir, SymbolicLink link, int linkDepth)
      Returns the directory entry located by the target path of the given symbolic link, resolved relative to the given directory.
      private @Nullable DirectoryEntry getRealEntry​(DirectoryEntry entry)
      Returns the entry for the file in its parent directory.
      @Nullable DirectoryEntry getRoot​(Name name)
      Gets the directory entry for the root with the given name or null if no such root exists.
      com.google.common.collect.ImmutableSortedSet<Name> getRootDirectoryNames()
      Returns the names of the root directories in this tree.
      private static boolean isEmpty​(com.google.common.collect.ImmutableList<Name> names)  
      DirectoryEntry lookUp​(File workingDirectory, JimfsPath path, java.util.Set<? super java.nio.file.LinkOption> options)
      Returns the result of the file lookup for the given path.
      private @Nullable DirectoryEntry lookUp​(File dir, JimfsPath path, java.util.Set<? super java.nio.file.LinkOption> options, int linkDepth)  
      private @Nullable DirectoryEntry lookUp​(File dir, java.lang.Iterable<Name> names, java.util.Set<? super java.nio.file.LinkOption> options, int linkDepth)
      Looks up the given names against the given base file.
      private @Nullable DirectoryEntry lookUpLast​(@Nullable File dir, Name name, java.util.Set<? super java.nio.file.LinkOption> options, int linkDepth)
      Looks up the last element of a path.
      private @Nullable Directory toDirectory​(@Nullable File file)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MAX_SYMBOLIC_LINK_DEPTH

        private static final int MAX_SYMBOLIC_LINK_DEPTH
        Doesn't much matter, but this number comes from MIN_ELOOP_THRESHOLD here
        See Also:
        Constant Field Values
      • EMPTY_PATH_NAMES

        private static final com.google.common.collect.ImmutableList<Name> EMPTY_PATH_NAMES
      • roots

        private final com.google.common.collect.ImmutableSortedMap<Name,​Directory> roots
        Map of root names to root directories.
    • Constructor Detail

      • FileTree

        FileTree​(java.util.Map<Name,​Directory> roots)
        Creates a new file tree with the given root directories.
    • Method Detail

      • getRootDirectoryNames

        public com.google.common.collect.ImmutableSortedSet<Name> getRootDirectoryNames()
        Returns the names of the root directories in this tree.
      • getRoot

        public @Nullable DirectoryEntry getRoot​(Name name)
        Gets the directory entry for the root with the given name or null if no such root exists.
      • lookUp

        public DirectoryEntry lookUp​(File workingDirectory,
                                     JimfsPath path,
                                     java.util.Set<? super java.nio.file.LinkOption> options)
                              throws java.io.IOException
        Returns the result of the file lookup for the given path.
        Throws:
        java.io.IOException
      • lookUp

        private @Nullable DirectoryEntry lookUp​(File dir,
                                                JimfsPath path,
                                                java.util.Set<? super java.nio.file.LinkOption> options,
                                                int linkDepth)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • lookUp

        private @Nullable DirectoryEntry lookUp​(File dir,
                                                java.lang.Iterable<Name> names,
                                                java.util.Set<? super java.nio.file.LinkOption> options,
                                                int linkDepth)
                                         throws java.io.IOException
        Looks up the given names against the given base file. If the file is not a directory, the lookup fails.
        Throws:
        java.io.IOException
      • lookUpLast

        private @Nullable DirectoryEntry lookUpLast​(@Nullable File dir,
                                                    Name name,
                                                    java.util.Set<? super java.nio.file.LinkOption> options,
                                                    int linkDepth)
                                             throws java.io.IOException
        Looks up the last element of a path.
        Throws:
        java.io.IOException
      • followSymbolicLink

        private @Nullable DirectoryEntry followSymbolicLink​(File dir,
                                                            SymbolicLink link,
                                                            int linkDepth)
                                                     throws java.io.IOException
        Returns the directory entry located by the target path of the given symbolic link, resolved relative to the given directory.
        Throws:
        java.io.IOException
      • getRealEntry

        private @Nullable DirectoryEntry getRealEntry​(DirectoryEntry entry)
        Returns the entry for the file in its parent directory. This will be the given entry unless the name for the entry is "." or "..", in which the directory linking to the file is not the file's parent directory. In that case, we know the file must be a directory ("." and ".." can only link to directories), so we can just get the entry in the directory's parent directory that links to it. So, for example, if we have a directory "foo" that contains a directory "bar" and we find an entry [bar -> "." -> bar], we instead return the entry for bar in its parent, [foo -> "bar" -> bar].
      • toDirectory

        private @Nullable Directory toDirectory​(@Nullable File file)
      • isEmpty

        private static boolean isEmpty​(com.google.common.collect.ImmutableList<Name> names)