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 (methods are synchronized).
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,ghidra.formats.gfilesystem.FileSystemIndexHelper.FileData<METADATATYPE>>>
directoryToListing
protected java.util.Map<java.lang.Long,ghidra.formats.gfilesystem.FileSystemIndexHelper.FileData<METADATATYPE>>
fileIndexToEntryMap
protected java.util.Map<GFile,ghidra.formats.gfilesystem.FileSystemIndexHelper.FileData<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.GFile
getFileByIndex(long fileIndex)
Gets the GFile instance that was associated with the filesystem file index.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.void
setMetadata(GFile f, METADATATYPE metaData)
Sets the associated metadata blob for the specified file.GFile
storeFile(java.lang.String path, long fileIndex, boolean isDirectory, long length, METADATATYPE metadata)
Creates and stores a file entry into in-memory indexes.GFile
storeFileWithParent(java.lang.String filename, GFile parent, long fileIndex, boolean isDirectory, long length, METADATATYPE metadata)
Creates and stores a file entry into in-memory indexes.java.lang.String
toString()
void
updateFSRL(GFile file, FSRL newFSRL)
Updates the FSRL of a file already in the index.
-
-
-
Field Detail
-
fileToEntryMap
protected java.util.Map<GFile,ghidra.formats.gfilesystem.FileSystemIndexHelper.FileData<METADATATYPE>> fileToEntryMap
-
fileIndexToEntryMap
protected java.util.Map<java.lang.Long,ghidra.formats.gfilesystem.FileSystemIndexHelper.FileData<METADATATYPE>> fileIndexToEntryMap
-
directoryToListing
protected java.util.Map<GFile,java.util.Map<java.lang.String,ghidra.formats.gfilesystem.FileSystemIndexHelper.FileData<METADATATYPE>>> directoryToListing
-
-
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
-
setMetadata
public void setMetadata(GFile f, METADATATYPE metaData) throws java.io.IOException
Sets the associated metadata blob for the specified file.- Parameters:
f
- GFile to updatemetaData
- new metdata blob- Throws:
java.io.IOException
- if unknown file
-
getFileByIndex
public GFile getFileByIndex(long fileIndex)
Gets the GFile instance that was associated with the filesystem file index.- Parameters:
fileIndex
- index of the file in its filesystem- Returns:
- the associated GFile instance, 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 GFile storeFile(java.lang.String path, long fileIndex, boolean isDirectory, long length, METADATATYPE metadata)
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 slashesfileIndex
- the filesystem specific unique index for this file, or -1 if not availableisDirectory
- boolean true if the new file is a directorylength
- number of bytes in the file or -1 if not known or directorymetadata
- 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, long fileIndex, boolean isDirectory, long length, METADATATYPE metadata)
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 availableisDirectory
- boolean true if the new file is a directorylength
- number of bytes in the file or -1 if not known or directorymetadata
- opaque blob that will be stored and associated with the new GFile instance- Returns:
- new GFile instance
-
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
-
updateFSRL
public void updateFSRL(GFile file, FSRL newFSRL)
Updates the FSRL of a file already in the index.- Parameters:
file
- currentGFile
newFSRL
- the new FSRL the new file will be given
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-