Package ghidra.framework.store.local
Class LocalFileSystem
java.lang.Object
ghidra.framework.store.local.LocalFileSystem
- All Implemented Interfaces:
FileSystem
- Direct Known Subclasses:
IndexedLocalFileSystem
,MangledLocalFileSystem
LocalFileSystem
provides access to FolderItem's which
exist within a File-based directory structure. Although FolderItem
caching is highly recommended, it is not provided by this implementation
and should be provided by an encompassing set of folder/file objects.
A LocalFileSystem may optionally support version control of its FolderItem's. When versioned, FolderItem's must be checked-out to create new versions. When not versioned, the check-out mechanism is not used.
FileSystemListener's will only be notified of changes made by the associated LocalFileSystem instance. For this reason, it is important that proper measures are taken to prevent concurrent modification of the underlying files/directories by another instance or by any other means.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected final FileSystemEventManager
static final String
static final char
Hidden directory name prefix.static final String
Hidden item name prefix.protected final boolean
protected final boolean
protected final File
Fields inherited from interface ghidra.framework.store.FileSystem
SEPARATOR, SEPARATOR_CHAR
-
Constructor Summary
ModifierConstructorDescriptionprotected
Constructor for an empty read-only file-system.protected
LocalFileSystem
(String rootPath, boolean isVersioned, boolean readOnly, boolean enableAsyncronousDispatching) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addFileSystemListener
(FileSystemListener listener) Adds the given listener to be notified of file system changes.protected abstract LocalFileSystem.ItemStorage
allocateItemStorage
(String folderPath, String itemName) Allocate a new storage locationprotected void
Check to see if file-system has been disposed.protected void
createDatabase
(String parentPath, String name, String fileID, BufferFile bufferFile, String comment, String contentType, boolean resetDatabaseId, TaskMonitor monitor, String user) Create a new database item within the specified parent folder using the contents of the specified BufferFile.createDatabase
(String parentPath, String name, String fileID, String contentType, int bufferSize, String user, String projectPath) Create a new empty database item within the specified parent folder.createDataFile
(String parentPath, String name, InputStream istream, String comment, String contentType, TaskMonitor monitor) Creates a new empty data file within the specified parent folder.createFile
(String parentPath, String name, File packedFile, TaskMonitor monitor, String user) Creates a new file item from a packed file.createTemporaryDatabase
(String parentPath, String name, String fileID, BufferFile bufferFile, String contentType, boolean resetDatabaseId, TaskMonitor monitor) protected abstract void
deallocateItemStorage
(String folderPath, String itemName) Deallocate item storageprotected void
deleteEmptyVersionedFolders
(String folderPath) Remove the directory which corresponds to the specified folder path if it is empty.void
dispose()
Cleanup and release resourcesstatic final String
Escape hidden prefix chars in nameboolean
fileExists
(String folderPath, String name) Returns true if the file existsprotected void
fileIdChanged
(PropertyFile propertyFile, String oldFileId) Notification that FileID has been changed within propertyFileprotected abstract LocalFileSystem.ItemStorage
findItemStorage
(String folderPath, String itemName) Find an existing storage locationabstract boolean
folderExists
(String folderPath) Returns true if the folder specified by the path exists.Returns the FolderItem specified by its unique File-IDReturns the FolderItem in the given folder with the given nameString[]
getItemNames
(String folderPath) Returns a list of the folder item names contained in the given folder.abstract String[]
getItemNames
(String folderPath, boolean includeHiddenFiles) Returns a list of the folder items contained in the given folder.static LocalFileSystem
getLocalFileSystem
(String rootPath, boolean create, boolean isVersioned, boolean readOnly, boolean enableAsyncronousDispatching) Construct a local filesystem for existing dataabstract int
protected static final String
protected static final String
getParentPath
(String path) protected static final String
Returns the full path for a specific folder or itemGet user name associated with this filesystem.static final boolean
isHiddenDirName
(String name) Determines if the specified storage directory name corresponds to a hidden directory (includes both system and application hidden directories).boolean
isOnline()
Returns true if file-system is on-line.boolean
Returns true if file-system is read-only.static boolean
boolean
isShared()
Returns true if this file system is sharedstatic boolean
isValidNameCharacter
(char c) boolean
Returns true if the file-system requires check-outs when modifying folder items.protected void
itemDeleted
(String folderPath, String itemName) Notify the filesystem that the property file and associated data files for an item have been removed from the filesystem.protected void
log
(LocalFolderItem item, String msg, String user) boolean
void
Moves the specified item to a new folder.void
removeFileSystemListener
(FileSystemListener listener) Removes the listener from being notified of file system changes.void
setAssociatedRepositoryLogger
(RepositoryLogger repositoryLogger) Associate file system with a specific repository loggerstatic void
If set, the state of folder item resources will be continually refreshed.void
testValidName
(String name, boolean isPath) Validate a folder/item name or path.static final String
Unescape a non-hidden directory nameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ghidra.framework.store.FileSystem
createFolder, deleteFolder, getFolderNames, getItemCount, moveFolder, renameFolder
-
Field Details
-
HIDDEN_DIR_PREFIX_CHAR
public static final char HIDDEN_DIR_PREFIX_CHARHidden directory name prefix. Should only be prepended to an escaped base-name.- See Also:
-
HIDDEN_DIR_PREFIX
-
HIDDEN_ITEM_PREFIX
Hidden item name prefix.- See Also:
-
root
-
isVersioned
protected final boolean isVersioned -
readOnly
protected final boolean readOnly -
eventManager
-
-
Constructor Details
-
LocalFileSystem
protected LocalFileSystem(String rootPath, boolean isVersioned, boolean readOnly, boolean enableAsyncronousDispatching) throws FileNotFoundException Constructor.- Parameters:
rootPath
- root path directory.isVersioned
- if true item versioning will be enabled.readOnly
- if true modifications within this file-system will not be allowed and result in an ReadOnlyExceptionenableAsyncronousDispatching
- if true a separate dispatch thread will be used to notify listeners. If false, blocking notification will be performed.- Throws:
FileNotFoundException
- if specified rootPath does not exist
-
LocalFileSystem
protected LocalFileSystem()Constructor for an empty read-only file-system.
-
-
Method Details
-
getLocalFileSystem
public static LocalFileSystem getLocalFileSystem(String rootPath, boolean create, boolean isVersioned, boolean readOnly, boolean enableAsyncronousDispatching) throws IOException Construct a local filesystem for existing data- Parameters:
rootPath
-create
-isVersioned
-readOnly
-enableAsyncronousDispatching
-- Returns:
- local filesystem
- Throws:
FileNotFoundException
- if specified rootPath does not existIOException
- if error occurs while reading/writing index files
-
getUserName
Description copied from interface:FileSystem
Get user name associated with this filesystem. In the case of a remote filesystem this will correspond to the name used during login/authentication. A null value may be returned if user name unknown.- Specified by:
getUserName
in interfaceFileSystem
-
cleanupAfterConstruction
protected void cleanupAfterConstruction() -
setAssociatedRepositoryLogger
Associate file system with a specific repository logger- Parameters:
repositoryLogger
-
-
log
-
setValidationRequired
public static void setValidationRequired()If set, the state of folder item resources will be continually refreshed. This is required if multiple instances exist for a single item. The default is disabled. This feature should be enabled for testing only since it may have a significant performance impact. This does not provide locking which may be required for a shared environment (e.g., checkin locking is only managed by a single instance). -
isRefreshRequired
public static boolean isRefreshRequired()- Returns:
- true if folder item resources must be refreshed.
- See Also:
-
isVersioned
public boolean isVersioned()Description copied from interface:FileSystem
Returns true if the file-system requires check-outs when modifying folder items.- Specified by:
isVersioned
in interfaceFileSystem
-
isOnline
public boolean isOnline()Description copied from interface:FileSystem
Returns true if file-system is on-line.- Specified by:
isOnline
in interfaceFileSystem
-
isReadOnly
public boolean isReadOnly()Description copied from interface:FileSystem
Returns true if file-system is read-only.- Specified by:
isReadOnly
in interfaceFileSystem
-
findItemStorage
protected abstract LocalFileSystem.ItemStorage findItemStorage(String folderPath, String itemName) throws FileNotFoundException Find an existing storage location- Parameters:
folderPath
-itemName
-- Returns:
- storage location. A non-null value does not guarantee that the associated item actually exists.
- Throws:
FileNotFoundException
-
allocateItemStorage
protected abstract LocalFileSystem.ItemStorage allocateItemStorage(String folderPath, String itemName) throws IOException, InvalidNameException Allocate a new storage location- Parameters:
folderPath
-itemName
-- Returns:
- storage location
- Throws:
DuplicateFileException
- if item path has previously been allocatedIOException
- if invalid path/item name specifiedInvalidNameException
- if folderPath or itemName contains invalid characters
-
deallocateItemStorage
protected abstract void deallocateItemStorage(String folderPath, String itemName) throws IOException Deallocate item storage- Parameters:
folderPath
-itemName
-- Throws:
IOException
-
getItemNames
public abstract String[] getItemNames(String folderPath, boolean includeHiddenFiles) throws IOException - Throws:
IOException
-
getItemNames
Description copied from interface:FileSystem
Returns a list of the folder item names contained in the given folder.- Specified by:
getItemNames
in interfaceFileSystem
- Parameters:
folderPath
- the path of the folder.- Returns:
- a list of folder item names.
- Throws:
IOException
-
getItem
Description copied from interface:FileSystem
Returns the FolderItem in the given folder with the given name- Specified by:
getItem
in interfaceFileSystem
- Parameters:
folderPath
- the folder path containing the item.name
- the name of the item.- Returns:
- the FolderItem with the given folderPath and name, or null if it doesn't exist.
- Throws:
IOException
- if IO error occurs.
-
fileIdChanged
Notification that FileID has been changed within propertyFile- Parameters:
propertyFile
-oldFileId
-- Throws:
IOException
-
getItem
Description copied from interface:FileSystem
Returns the FolderItem specified by its unique File-ID- Specified by:
getItem
in interfaceFileSystem
- Parameters:
fileID
- the items unique file ID- Returns:
- the FolderItem with the given folderPath and name, or null if it doesn't exist.
- Throws:
IOException
- if IO error occurs.UnsupportedOperationException
- if file-system does not support this operation
-
getItems
Description copied from interface:FileSystem
Returns a list of the folder items contained in the given folder.- Specified by:
getItems
in interfaceFileSystem
- Parameters:
folderPath
- the path of the folder.- Returns:
- a list of folder items.
- Throws:
IOException
-
createDatabase
public LocalDatabaseItem createDatabase(String parentPath, String name, String fileID, BufferFile bufferFile, String comment, String contentType, boolean resetDatabaseId, TaskMonitor monitor, String user) throws InvalidNameException, IOException, CancelledException Description copied from interface:FileSystem
Create a new database item within the specified parent folder using the contents of the specified BufferFile.- Specified by:
createDatabase
in interfaceFileSystem
- Parameters:
parentPath
- folder path of parentname
- new database namefileID
- file ID to be associated with new database or nullbufferFile
- data sourcecomment
- version comment (used for versioned file system only)contentType
- application defined content typeresetDatabaseId
- if true database ID will be reset for new Databasemonitor
- allows the database copy to be monitored and cancelled.user
- name of user creating item (required for versioned item)- Returns:
- new DatabaseItem
- Throws:
InvalidNameException
- if the name does not have all alphanumericsIOException
- if an IO error occurs.CancelledException
- if cancelled by monitor
-
createTemporaryDatabase
public LocalDatabaseItem createTemporaryDatabase(String parentPath, String name, String fileID, BufferFile bufferFile, String contentType, boolean resetDatabaseId, TaskMonitor monitor) throws InvalidNameException, IOException, CancelledException -
createDatabase
public LocalManagedBufferFile createDatabase(String parentPath, String name, String fileID, String contentType, int bufferSize, String user, String projectPath) throws InvalidNameException, IOException Description copied from interface:FileSystem
Create a new empty database item within the specified parent folder. If this is a versioned file-system, the associated item is checked-out. The resulting checkoutId can be obtained from the returned buffer file.- Specified by:
createDatabase
in interfaceFileSystem
- Parameters:
parentPath
- folder path of parentname
- new database namefileID
- file ID to be associated with new database or nullcontentType
- application defined content typebufferSize
- buffer size. If copying an existing BufferFile, the buffer size must be the same as the source file.user
- name of user creating item (required for versioned item)projectPath
- path of project in which database is checked-out (required for versioned item)- Returns:
- an empty BufferFile open for read-write.
- Throws:
InvalidNameException
- if the name does not have all alphanumericsIOException
- if an IO error occurs.
-
createDataFile
public LocalDataFile createDataFile(String parentPath, String name, InputStream istream, String comment, String contentType, TaskMonitor monitor) throws InvalidNameException, IOException, CancelledException Description copied from interface:FileSystem
Creates a new empty data file within the specified parent folder.- Specified by:
createDataFile
in interfaceFileSystem
- Parameters:
parentPath
- folder path of parentname
- new data file nameistream
- source datacomment
- version comment (used for versioned file system only)contentType
- application defined content typemonitor
- progress monitor (used for cancel support, progress not used since length of input stream is unknown)- Returns:
- new data file
- Throws:
InvalidNameException
- if the name has illegal characters. all alphanumericsIOException
- if an IO error occurs.CancelledException
- if cancelled by monitor
-
createFile
public LocalDatabaseItem createFile(String parentPath, String name, File packedFile, TaskMonitor monitor, String user) throws InvalidNameException, IOException, CancelledException Description copied from interface:FileSystem
Creates a new file item from a packed file. The content/item type must be determined from the input stream.- Specified by:
createFile
in interfaceFileSystem
- Parameters:
parentPath
- folder path of parentname
- new data file namepackedFile
- packed file datamonitor
- progress monitor (used for cancel support, progress not used since length of input stream is unknown)user
- name of user creating item (required for versioned item)- Returns:
- new item
- Throws:
InvalidNameException
- if the name has illegal characters. all alphanumericsIOException
- if an IO error occurs.CancelledException
- if cancelled by monitor
-
moveItem
public void moveItem(String folderPath, String name, String newFolderPath, String newName) throws IOException, InvalidNameException Description copied from interface:FileSystem
Moves the specified item to a new folder.- Specified by:
moveItem
in interfaceFileSystem
- Parameters:
folderPath
- path of folder containing the item.name
- name of the item to be moved.newFolderPath
- path of folder where item is to be moved.- Throws:
IOException
- if an IO error occurs.InvalidNameException
- if the newName is invalid
-
folderExists
Description copied from interface:FileSystem
Returns true if the folder specified by the path exists.- Specified by:
folderExists
in interfaceFileSystem
- Parameters:
folderPath
- the name of the folder to check for existence.- Returns:
- true if the folder exists.
-
fileExists
Description copied from interface:FileSystem
Returns true if the file exists- Specified by:
fileExists
in interfaceFileSystem
- Parameters:
folderPath
- the folderPath of the folder that may contain the file.name
- the name of the file to check for existence.
-
addFileSystemListener
Description copied from interface:FileSystem
Adds the given listener to be notified of file system changes.- Specified by:
addFileSystemListener
in interfaceFileSystem
- Parameters:
listener
- the listener to be added.
-
removeFileSystemListener
Description copied from interface:FileSystem
Removes the listener from being notified of file system changes.- Specified by:
removeFileSystemListener
in interfaceFileSystem
- Parameters:
listener
-
-
getMaxNameLength
public abstract int getMaxNameLength()- Returns:
- the maximum name length permitted for folders or items.
-
testValidName
Validate a folder/item name or path.- Parameters:
name
- folder or item nameisPath
- if true name represents full path- Throws:
InvalidNameException
- if name is invalid
-
isValidNameCharacter
public static boolean isValidNameCharacter(char c) - Returns:
- true if c is a valid character within the FileSystem.
-
deleteEmptyVersionedFolders
Remove the directory which corresponds to the specified folder path if it is empty. If folder directory is removed, this method is invoked recursively for parent folder path which may also be removed if it is empty. This method is intended for use with a versioned file system which only retains folders if they contain one or more items or sub-folders.- Parameters:
folderPath
- folder path
-
itemDeleted
Notify the filesystem that the property file and associated data files for an item have been removed from the filesystem.- Parameters:
folderPath
-itemName
-- Throws:
IOException
-
getPath
Returns the full path for a specific folder or item- Parameters:
parentPath
- full parent pathname
- child folder or item name
-
getParentPath
-
getName
-
dispose
public void dispose()Description copied from interface:FileSystem
Cleanup and release resources- Specified by:
dispose
in interfaceFileSystem
-
checkDisposed
Check to see if file-system has been disposed.- Throws:
IOException
- if file-system has been disposed
-
migrationInProgress
public boolean migrationInProgress() -
isHiddenDirName
Determines if the specified storage directory name corresponds to a hidden directory (includes both system and application hidden directories).- Parameters:
name
- directory name as it appears on storage file system.- Returns:
- true if name is a hidden name, else false
-
escapeHiddenDirPrefixChars
Escape hidden prefix chars in name- Parameters:
name
-- Returns:
- escaped name
-
unescapeHiddenDirPrefixChars
Unescape a non-hidden directory name- Parameters:
name
-- Returns:
- unescaped name or null if name is a hidden name
-