Class FileSystemIndexHelper<METADATATYPE>
- java.lang.Object
-
- ghidra.formats.gfilesystem.FileSystemIndexHelper<METADATATYPE>
-
- Type Parameters:
METADATATYPE
- the filesystem specific native file object that the user of this class wants to be able to correlate with GhidraGFile
instances.
public class FileSystemIndexHelper<METADATATYPE> extends java.lang.Object
A helper class used by GFilesystem implementors to track mappings between GFile instances and the underlying container filesystem's native file objects.Threadsafe after initial use of
storeFile()
by the owning filesystem.This class also provides filename 'unique-ifying' (per directory) where an auto-incrementing number will be added to a file's filename if it is not unique in the directory.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<GFile,java.util.Map<java.lang.String,GFile>>
directoryToListing
protected java.util.Map<GFile,METADATATYPE>
fileToEntryMap
-
Constructor Summary
Constructors Constructor Description FileSystemIndexHelper(GFileSystem fs, FSRLRoot fsFSRL)
Creates a newFileSystemIndexHelper
for the specifiedGFileSystem
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Removes all file info from this index.protected GFileImpl
createNewFile(GFile parentFile, java.lang.String name, boolean isDirectory, long size, METADATATYPE metadata)
Creates a new GFile instance, using per-filesystem custom logic.protected java.util.Map<java.lang.String,GFile>
getDirectoryContents(GFile directoryFile, boolean createIfMissing)
Returns a string->GFile map that holds the contents of a single directory.int
getFileCount()
Number of files in this index.java.util.List<GFile>
getListing(GFile directory)
Mirror'sGFileSystem.getListing(GFile)
interface.METADATATYPE
getMetadata(GFile f)
Gets the opaque filesystem specific blob that was associated with the specified file.GFile
getRootDir()
Gets the rootGFile
object for this filesystem index.GFile
lookup(java.lang.String path)
Mirror'sGFileSystem.lookup(String)
interface.protected GFile
lookupParent(java.lang.String[] nameparts)
Walks a list of names of directories in nameparts (stopping prior to the last element) starting at the root of the filesystem and returns the final directory.GFileImpl
storeFile(java.lang.String path, int fileIndex, boolean isDirectory, long length, METADATATYPE fileInfo)
Creates and stores a file entry into in-memory indexes.GFile
storeFileWithParent(java.lang.String filename, GFile parent, int fileIndex, boolean isDirectory, long length, METADATATYPE fileInfo)
Creates and stores a file entry into in-memory indexes.java.lang.String
toString()
-
-
-
Field Detail
-
fileToEntryMap
protected java.util.Map<GFile,METADATATYPE> fileToEntryMap
-
-
Constructor Detail
-
FileSystemIndexHelper
public FileSystemIndexHelper(GFileSystem fs, FSRLRoot fsFSRL)
Creates a newFileSystemIndexHelper
for the specifiedGFileSystem
.A "root" directory GFile will be auto-created for the filesystem.
- Parameters:
fs
- theGFileSystem
that this index will be for.fsFSRL
- thefsrl
of the filesystem itself. (this parameter is explicitly passed here so there is no possibility of trying to call back to the fs'sGFileSystem.getFSRL()
on a half-constructed filesystem.)
-
-
Method Detail
-
getRootDir
public GFile getRootDir()
Gets the rootGFile
object for this filesystem index.- Returns:
- root
GFile
object.
-
clear
public void clear()
Removes all file info from this index.
-
getFileCount
public int getFileCount()
Number of files in this index.- Returns:
- number of file in this index.
-
getMetadata
public METADATATYPE getMetadata(GFile f)
Gets the opaque filesystem specific blob that was associated with the specified file.- Parameters:
f
-GFile
to look for.- Returns:
- Filesystem specific blob associated with the specified file, or null if not found.
-
getListing
public java.util.List<GFile> getListing(GFile directory)
Mirror'sGFileSystem.getListing(GFile)
interface.- Parameters:
directory
-GFile
directory to get the list of child files that have been added to this index, null means root directory.- Returns:
List
of GFile files that are in the specified directory, never null.
-
lookup
public GFile lookup(java.lang.String path)
Mirror'sGFileSystem.lookup(String)
interface.- Parameters:
path
- path and filename of a file to find.- Returns:
GFile
instance or null if no file was added to the index at that path.
-
storeFile
public GFileImpl storeFile(java.lang.String path, int fileIndex, boolean isDirectory, long length, METADATATYPE fileInfo)
Creates and stores a file entry into in-memory indexes.The string path will be normalized to forward slashes before being split into directory components.
Filenames that are not unique in their directory will have a "[nnn]" suffix added to the resultant GFile name, where nnn is the file's order of occurrence in the container file.
- Parameters:
path
- string path and filename of the file being added to the index. Back slashes are normalized to forward slashes.fileIndex
- the filesystem specific unique index for this file, or -1 if not available.isDirectory
- boolean true if the new file is a directorylength
- number of bytes in the file or -1 if not known or directory.fileInfo
- opaque blob that will be stored and associated with the new GFile instance.- Returns:
- new GFile instance.
-
storeFileWithParent
public GFile storeFileWithParent(java.lang.String filename, GFile parent, int fileIndex, boolean isDirectory, long length, METADATATYPE fileInfo)
Creates and stores a file entry into in-memory indexes.Use this when you already know the parent directory GFile object.
Filenames that are not unique in their directory will have a "[nnn]" suffix added to the resultant GFile name, where nnn is the file's order of occurrence in the container file.
- Parameters:
filename
- the new file's nameparent
- the new file's parent directoryfileIndex
- the filesystem specific unique index for this file, or -1 if not available.isDirectory
- boolean true if the new file is a directorylength
- number of bytes in the file or -1 if not known or directory.fileInfo
- opaque blob that will be stored and associated with the new GFile instance.- Returns:
- new GFile instance.
-
getDirectoryContents
protected java.util.Map<java.lang.String,GFile> getDirectoryContents(GFile directoryFile, boolean createIfMissing)
Returns a string->GFile map that holds the contents of a single directory.- Parameters:
directoryFile
-- Returns:
-
lookupParent
protected GFile lookupParent(java.lang.String[] nameparts)
Walks a list of names of directories in nameparts (stopping prior to the last element) starting at the root of the filesystem and returns the final directory.Directories in a path that have not been encountered before (ie. a file's path references a directory that hasn't been mentioned yet as its own file entry) will have a stub entry GFile created for them.
Superfluous slashes in the original filename (ie. name/sub//subafter_extra_slash) will be represented as empty string elements in the nameparts array and will be skipped as if they were not there.
- Parameters:
nameparts
-- Returns:
-
createNewFile
protected GFileImpl createNewFile(GFile parentFile, java.lang.String name, boolean isDirectory, long size, METADATATYPE metadata)
Creates a new GFile instance, using per-filesystem custom logic.- Parameters:
parentFile
- the parent file of the new instance. Never null.name
- the name of the fileisDirectory
- is this is file or directory?size
- length of the file datametadata
- filesystem specific BLOB that may have data that this method needs to create the new GFile instance. Can be null if this method is being called to create a missing directory that was referenced in a filename.- Returns:
- new GFileImpl instance
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-