Package ghidra.formats.gfilesystem

# Class LocalFileSystem

java.lang.Object
ghidra.formats.gfilesystem.LocalFileSystem

All Implemented Interfaces:
  `GFileHashProvider`, `GFileSystem`, `ExtensionPoint`, `Closeable`, `AutoCloseable`

public class LocalFileSystem extends Object implements GFileSystem, GFileHashProvider
A `GFileSystem` implementation giving access to the user's operating system's local file system.

This implementation does not have a `GFileSystemFactory` as this class will be used as the single root filesystem.

Closing() this filesystem does nothing.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `FSTYPE`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  `ByteProvider`
  `getByteProvider(GFile file, TaskMonitor monitor)`
  Returns a `ByteProvider` that contains the contents of the specified `GFile`.
  `FileAttributes`
  `getFileAttributes(GFile file, TaskMonitor monitor)`
  Returns a container of `FileAttribute` values.
  `FileAttributes`
  `getFileAttributes(File f)`
  Create a `FileAttributes` container with info about the specified local file.
  `FSRLRoot`
  `getFSRL()`
  File system's FSRL
  `InputStream`
  `getInputStream(GFile file, TaskMonitor monitor)`
  Returns an `InputStream` that contains the contents of the specified `GFile`.
  `List<GFile>`
  `getListing(GFile directory)`
  Returns a list of `files` that reside in the specified directory on this filesystem.
  `File`
  `getLocalFile(FSRL fsrl)`
  Convert a FSRL that points to this file system into a java `File`.
  `FSRL`
  `getLocalFSRL(File f)`
  Converts a `File` into a `FSRL`.
  `String`
  `getMD5Hash(GFile file, boolean required, TaskMonitor monitor)`
  Returns the MD5 hash of the specified file.
  `String`
  `getName()`
  File system volume name.
  `FileSystemRefManager`
  `getRefManager()`
  Returns the `ref manager` that is responsible for creating and releasing `refs` to this filesystem.
  `LocalFileSystemSub`
  `getSubFileSystem(FSRL fsrl)`
  Creates a new file system instance that is a sub-view limited to the specified directory.
  `boolean`
  `isClosed()`
  Returns true if the filesystem has been `closed`
  `boolean`
  `isLocalSubdir(FSRL fsrl)`
  Returns true if the `FSRL` is a local filesystem subdirectory.
  `boolean`
  `isStatic()`
  Indicates if this filesystem is a static snapshot or changes.
  `GFile`
  `lookup(String path)`
  Retrieves a `GFile` from this filesystem based on its full path and filename, using this filesystem's default name comparison logic (eg.
  `static File`
  `lookupFile(File baseDir, String path, Comparator<String> nameComp)`
  Looks up a file, by its string path, using a custom comparator.
  `static LocalFileSystem`
  `makeGlobalRootFS()`
  Create a new instance
  `String`
  `toString()`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface ghidra.formats.gfilesystem.GFileSystem

  `getDescription, getFileCount, getType`

- ## Field Details

  - ### FSTYPE

    public static final String FSTYPE
    See Also:
      - Constant Field Values

- ## Method Details

  - ### makeGlobalRootFS

    public static LocalFileSystem makeGlobalRootFS()
    Create a new instance
    Returns:
      new `LocalFileSystem` instance using `FSTYPE` as its FSRL type.

  - ### getSubFileSystem

    public LocalFileSystemSub getSubFileSystem(FSRL fsrl) throws IOException
    Creates a new file system instance that is a sub-view limited to the specified directory.
    Parameters:
      `fsrl` - `FSRL` that must be a directory in this local filesystem
    Returns:
      new `LocalFileSystemSub` instance
    Throws:
      `IOException` - if bad FSRL

  - ### isLocalSubdir

    public boolean isLocalSubdir(FSRL fsrl)
    Returns true if the `FSRL` is a local filesystem subdirectory.
    Parameters:
      `fsrl` - `FSRL` to test.
    Returns:
      boolean true if local filesystem directory.

  - ### getLocalFile

    public File getLocalFile(FSRL fsrl) throws IOException
    Convert a FSRL that points to this file system into a java `File`.
    Parameters:
      `fsrl` - `FSRL`
    Returns:
      `File`
    Throws:
      `IOException` - if FSRL does not point to this file system

  - ### getLocalFSRL

    public FSRL getLocalFSRL(File f)
    Converts a `File` into a `FSRL`.

    NOTE: The given `File`'s absolute path will be used.

    Parameters:
      `f` - The `File` to convert to an `FSRL`
    Returns:
      The `FSRL`

  - ### getName

    public String getName()
    Description copied from interface: `GFileSystem`
    File system volume name.

    Typically the name of the container file, or a internally stored 'volume' name.

    Specified by:
      `getName` in interface `GFileSystem`
    Returns:
      string filesystem volume name.

  - ### close

    public void close()
    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `Closeable`

  - ### isStatic

    public boolean isStatic()
    Description copied from interface: `GFileSystem`
    Indicates if this filesystem is a static snapshot or changes.
    Specified by:
      `isStatic` in interface `GFileSystem`
    Returns:
      boolean true if the filesystem is static or false if dynamic content.

  - ### getListing

    public List<GFile> getListing(GFile directory)
    Description copied from interface: `GFileSystem`
    Returns a list of `files` that reside in the specified directory on this filesystem.

    Specified by:
      `getListing` in interface `GFileSystem`
    Parameters:
      `directory` - NULL means root of filesystem.
    Returns:
      `List` of `GFile` instances of file in the requested directory.

  - ### getFileAttributes

    public FileAttributes getFileAttributes(GFile file, TaskMonitor monitor)
    Description copied from interface: `GFileSystem`
    Returns a container of `FileAttribute` values.

    Implementors of this method are not required to add FSRL, NAME, or PATH values unless the values are non-standard.

    Specified by:
      `getFileAttributes` in interface `GFileSystem`
    Parameters:
      `file` - `GFile` to get the attributes for
      `monitor` - `TaskMonitor`
    Returns:
      `FileAttributes` instance (possibly read-only), maybe empty but never null

  - ### getFileAttributes

    public FileAttributes getFileAttributes(File f)
    Create a `FileAttributes` container with info about the specified local file.
    Parameters:
      `f` - `File` to query
    Returns:
      `FileAttributes` instance

  - ### getFSRL

    public FSRLRoot getFSRL()
    Description copied from interface: `GFileSystem`
    File system's FSRL
    Specified by:
      `getFSRL` in interface `GFileSystem`
    Returns:
      `FSRLRoot` of this filesystem.

  - ### lookup

    public GFile lookup(String path) throws IOException
    Description copied from interface: `GFileSystem`
    Retrieves a `GFile` from this filesystem based on its full path and filename, using this filesystem's default name comparison logic (eg. case sensitive vs insensitive).

    Specified by:
      `lookup` in interface `GFileSystem`
    Parameters:
      `path` - string path and filename of a file located in this filesystem. Use `null` or "/" to retrieve the root directory
    Returns:
      `GFile` instance of requested file, null if not found.
    Throws:
      `IOException` - if IO error when looking up file.

  - ### isClosed

    public boolean isClosed()
    Description copied from interface: `GFileSystem`
    Returns true if the filesystem has been `closed`
    Specified by:
      `isClosed` in interface `GFileSystem`
    Returns:
      boolean true if the filesystem has been closed.

  - ### getRefManager

    public FileSystemRefManager getRefManager()
    Description copied from interface: `GFileSystem`
    Returns the `ref manager` that is responsible for creating and releasing `refs` to this filesystem.

    Specified by:
      `getRefManager` in interface `GFileSystem`
    Returns:
      `FileSystemRefManager` that manages references to this filesystem.

  - ### getInputStream

    public InputStream getInputStream(GFile file, TaskMonitor monitor) throws IOException
    Description copied from interface: `GFileSystem`
    Returns an `InputStream` that contains the contents of the specified `GFile`.

    The caller is responsible for closing the stream.

    Specified by:
      `getInputStream` in interface `GFileSystem`
    Parameters:
      `file` - `GFile` to get an InputStream for
      `monitor` - `TaskMonitor` to watch and update progress
    Returns:
      new `InputStream` contains the contents of the file or NULL if the file doesn't have data.
    Throws:
      `IOException` - if IO problem

  - ### getByteProvider

    public ByteProvider getByteProvider(GFile file, TaskMonitor monitor) throws IOException
    Description copied from interface: `GFileSystem`
    Returns a `ByteProvider` that contains the contents of the specified `GFile`.

    The caller is responsible for closing the provider.

    Specified by:
      `getByteProvider` in interface `GFileSystem`
    Parameters:
      `file` - `GFile` to get bytes for
      `monitor` - `TaskMonitor` to watch and update progress
    Returns:
      new `ByteProvider` that contains the contents of the file, or NULL if file doesn't have data
    Throws:
      `IOException` - if error

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### getMD5Hash

    public String getMD5Hash(GFile file, boolean required, TaskMonitor monitor) throws CancelledException, IOException
    Description copied from interface: `GFileHashProvider`
    Returns the MD5 hash of the specified file.
    Specified by:
      `getMD5Hash` in interface `GFileHashProvider`
    Parameters:
      `file` - the `GFile`
      `required` - boolean flag, if true the hash will always be returned, even if it has to be calculated. If false, the hash will be returned if easily available
      `monitor` - `TaskMonitor`
    Returns:
      MD5 hash as a string
    Throws:
      `CancelledException` - if cancelled
      `IOException` - if error

  - ### lookupFile

    public static File lookupFile(File baseDir, String path, Comparator<String> nameComp)
    Looks up a file, by its string path, using a custom comparator.

    If any element of the path, or the filename are not found, returns a null.

    A null custom comparator avoids testing each element of the directory path and instead relies on the native local file system's name matching.

    Parameters:
      `baseDir` - optional directory to start lookup at
      `path` - String path
      `nameComp` - optional `Comparator` that will compare filenames, or `null` to use native local file system lookup (eg. case-insensitive on windows)
    Returns:
      File that points to the requested path, or null if file was not present on the local filesystem (because it doesn't exist, or the name comparison function rejected it)