Class LocalFileSystem
- All Implemented Interfaces:
GFileHashProvider,GFileSystem,ExtensionPoint,Closeable,AutoCloseable,Iterable<GFile>
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()getByteProvider(GFile file, TaskMonitor monitor) Returns aByteProviderthat contains the contents of the specifiedGFile.getFileAttributes(GFile file, TaskMonitor monitor) Returns a container ofFileAttributevalues.Create aFileAttributescontainer with info about the specified local file.getFSRL()File system's FSRLgetInputStream(GFile file, TaskMonitor monitor) Returns anInputStreamthat contains the contents of the specifiedGFile.getListing(GFile directory) Returns a list offilesthat reside in the specified directory on this filesystem.getLocalFile(FSRL fsrl) Convert a FSRL that points to this file system into a javaFile.getLocalFSRL(File f) getMD5Hash(GFile file, boolean required, TaskMonitor monitor) Returns the MD5 hash of the specified file.getName()File system volume name.Returns theref managerthat is responsible for creating and releasingrefsto this filesystem.Returns the file system's root directory.getSubFileSystem(FSRL fsrl) Creates a new file system instance that is a sub-view limited to the specified directory.booleanisClosed()Returns true if the filesystem has beenclosedbooleanisLocalSubdir(FSRL fsrl) Returns true if theFSRLis a local filesystem subdirectory.booleanisStatic()Indicates if this filesystem is a static snapshot or changes.Retrieves aGFilefrom this filesystem based on its full path and filename, using this filesystem's default name comparison logic (eg.lookup(String path, Comparator<String> nameComp) Retrieves aGFilefrom this filesystem based on its full path and filename, using the specified name comparison logic (eg.static FilelookupFile(File baseDir, String path, Comparator<String> nameComp) Looks up a file, by its string path, using a custom comparator.static LocalFileSystemCreate a new instanceresolveSymlinks(GFile file) Converts the specified (symlink) file into it's destination, or if not a symlink, returns the original file unchanged.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ghidra.formats.gfilesystem.GFileSystem
files, files, files, files, getDescription, getFileCount, getType, iteratorMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
FSTYPE
- See Also:
-
-
Method Details
-
makeGlobalRootFS
Create a new instance- Returns:
- new
LocalFileSysteminstance usingFSTYPEas its FSRL type.
-
getSubFileSystem
Creates a new file system instance that is a sub-view limited to the specified directory.- Parameters:
fsrl-FSRLthat must be a directory in this local filesystem- Returns:
- new
LocalFileSystemSubinstance - Throws:
IOException- if bad FSRL
-
isLocalSubdir
Returns true if theFSRLis a local filesystem subdirectory.- Parameters:
fsrl-FSRLto test.- Returns:
- boolean true if local filesystem directory.
-
getLocalFile
Convert a FSRL that points to this file system into a javaFile.- Parameters:
fsrl-FSRL- Returns:
File- Throws:
IOException- if FSRL does not point to this file system
-
getLocalFSRL
-
getName
Description copied from interface:GFileSystemFile system volume name.Typically the name of the container file, or a internally stored 'volume' name.
- Specified by:
getNamein interfaceGFileSystem- Returns:
- string filesystem volume name.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
isStatic
public boolean isStatic()Description copied from interface:GFileSystemIndicates if this filesystem is a static snapshot or changes.- Specified by:
isStaticin interfaceGFileSystem- Returns:
- boolean true if the filesystem is static or false if dynamic content.
-
getListing
Description copied from interface:GFileSystemReturns a list offilesthat reside in the specified directory on this filesystem.- Specified by:
getListingin interfaceGFileSystem- Parameters:
directory- NULL means root of filesystem.- Returns:
ListofGFileinstances of file in the requested directory.
-
getFileAttributes
Description copied from interface:GFileSystemReturns a container ofFileAttributevalues.Implementors of this method are not required to add FSRL, NAME, or PATH values unless the values are non-standard.
- Specified by:
getFileAttributesin interfaceGFileSystem- Parameters:
file-GFileto get the attributes formonitor-TaskMonitor- Returns:
FileAttributesinstance (possibly read-only), maybe empty but never null
-
getFileAttributes
Create aFileAttributescontainer with info about the specified local file.- Parameters:
f-Fileto query- Returns:
FileAttributesinstance
-
getFSRL
Description copied from interface:GFileSystemFile system's FSRL- Specified by:
getFSRLin interfaceGFileSystem- Returns:
FSRLRootof this filesystem.
-
getRootDir
Description copied from interface:GFileSystemReturns the file system's root directory.Note: using
nullwhen callingGFileSystem.getListing(GFile)is also valid.- Specified by:
getRootDirin interfaceGFileSystem- Returns:
- file system's root directory
-
lookup
Description copied from interface:GFileSystemRetrieves aGFilefrom this filesystem based on its full path and filename, using this filesystem's default name comparison logic (eg. case sensitive vs insensitive).- Specified by:
lookupin interfaceGFileSystem- Parameters:
path- string path and filename of a file located in this filesystem. Usenullor "/" to retrieve the root directory- Returns:
GFileinstance of requested file, null if not found.- Throws:
IOException- if IO error when looking up file.
-
lookup
Description copied from interface:GFileSystemRetrieves aGFilefrom this filesystem based on its full path and filename, using the specified name comparison logic (eg. case sensitive vs insensitive).- Specified by:
lookupin interfaceGFileSystem- Parameters:
path- string path and filename of a file located in this filesystem. Usenullor "/" to retrieve the root directorynameComp- string comparator used to compare filenames. Usenullto specify the file system's native comparison logic.- Returns:
GFileinstance of requested file, null if not found.- Throws:
IOException- if IO error when looking up file.
-
isClosed
public boolean isClosed()Description copied from interface:GFileSystemReturns true if the filesystem has beenclosed- Specified by:
isClosedin interfaceGFileSystem- Returns:
- boolean true if the filesystem has been closed.
-
getRefManager
Description copied from interface:GFileSystemReturns theref managerthat is responsible for creating and releasingrefsto this filesystem.- Specified by:
getRefManagerin interfaceGFileSystem- Returns:
FileSystemRefManagerthat manages references to this filesystem.
-
getInputStream
Description copied from interface:GFileSystemReturns anInputStreamthat contains the contents of the specifiedGFile.The caller is responsible for closing the stream.
- Specified by:
getInputStreamin interfaceGFileSystem- Parameters:
file-GFileto get an InputStream formonitor-TaskMonitorto watch and update progress- Returns:
- new
InputStreamcontains the contents of the file or NULL if the file doesn't have data. - Throws:
IOException- if IO problem
-
getByteProvider
Description copied from interface:GFileSystemReturns aByteProviderthat contains the contents of the specifiedGFile.The caller is responsible for closing the provider.
- Specified by:
getByteProviderin interfaceGFileSystem- Parameters:
file-GFileto get bytes formonitor-TaskMonitorto watch and update progress- Returns:
- new
ByteProviderthat contains the contents of the file, or NULL if file doesn't have data - Throws:
IOException- if error
-
resolveSymlinks
Description copied from interface:GFileSystemConverts the specified (symlink) file into it's destination, or if not a symlink, returns the original file unchanged.- Specified by:
resolveSymlinksin interfaceGFileSystem- Parameters:
file- symlink file to follow- Returns:
- destination of symlink, or original file if not a symlink
- Throws:
IOException- if error following symlink path, typically outside of the hosting file system
-
toString
-
getMD5Hash
public String getMD5Hash(GFile file, boolean required, TaskMonitor monitor) throws CancelledException, IOException Description copied from interface:GFileHashProviderReturns the MD5 hash of the specified file.- Specified by:
getMD5Hashin interfaceGFileHashProvider- Parameters:
file- theGFilerequired- 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 availablemonitor-TaskMonitor- Returns:
- MD5 hash as a string
- Throws:
CancelledException- if cancelledIOException- if error
-
lookupFile
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 atpath- String pathnameComp- optionalComparatorthat will compare filenames, ornullto 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)
-