Package ghidra.framework.store.local
Class LocalFileSystem
- java.lang.Object
-
- ghidra.framework.store.local.LocalFileSystem
-
- All Implemented Interfaces:
FileSystem
- Direct Known Subclasses:
IndexedLocalFileSystem,MangledLocalFileSystem
public abstract class LocalFileSystem extends java.lang.Object implements FileSystem
LocalFileSystemprovides 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
Nested Classes Modifier and Type Class Description protected static classLocalFileSystem.ItemStorage
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringHIDDEN_DIR_PREFIXstatic charHIDDEN_DIR_PREFIX_CHARHidden directory name prefix.static java.lang.StringHIDDEN_ITEM_PREFIXHidden item name prefix.protected booleanisVersionedprotected FileSystemListenerListlistenersprotected booleanreadOnlyprotected java.io.Fileroot-
Fields inherited from interface ghidra.framework.store.FileSystem
SEPARATOR, SEPARATOR_CHAR
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedLocalFileSystem()Constructor for an empty read-only file-system.protectedLocalFileSystem(java.lang.String rootPath, boolean isVersioned, boolean readOnly, boolean enableAsyncronousDispatching)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddFileSystemListener(FileSystemListener listener)Adds the given listener to be notified of file system changes.protected abstract LocalFileSystem.ItemStorageallocateItemStorage(java.lang.String folderPath, java.lang.String itemName)Allocate a new storage locationprotected voidcleanupAfterConstruction()LocalDatabaseItemcreateDatabase(java.lang.String parentPath, java.lang.String name, java.lang.String fileID, BufferFile bufferFile, java.lang.String comment, java.lang.String contentType, boolean resetDatabaseId, TaskMonitor monitor, java.lang.String user)Create a new database item within the specified parent folder using the contents of the specified BufferFile.LocalManagedBufferFilecreateDatabase(java.lang.String parentPath, java.lang.String name, java.lang.String fileID, java.lang.String contentType, int bufferSize, java.lang.String user, java.lang.String projectPath)Create a new empty database item within the specified parent folder.LocalDataFilecreateDataFile(java.lang.String parentPath, java.lang.String name, java.io.InputStream istream, java.lang.String comment, java.lang.String contentType, TaskMonitor monitor)Creates a new empty data file within the specified parent folder.LocalDatabaseItemcreateFile(java.lang.String parentPath, java.lang.String name, java.io.File packedFile, TaskMonitor monitor, java.lang.String user)Creates a new file item from a packed file.LocalDatabaseItemcreateTemporaryDatabase(java.lang.String parentPath, java.lang.String name, java.lang.String fileID, BufferFile bufferFile, java.lang.String contentType, boolean resetDatabaseId, TaskMonitor monitor)protected abstract voiddeallocateItemStorage(java.lang.String folderPath, java.lang.String itemName)Deallocate item storageprotected voiddeleteEmptyVersionedFolders(java.lang.String folderPath)Remove the directory which corresponds to the specified folder path if it is empty.voiddispose()Cleanup & release resourcesstatic java.lang.StringescapeHiddenDirPrefixChars(java.lang.String name)Escape hidden prefix chars in namebooleanfileExists(java.lang.String folderPath, java.lang.String name)Returns true if the file existsprotected voidfileIdChanged(PropertyFile propertyFile, java.lang.String oldFileId)Notification that FileID has been changed within propertyFileprotected abstract LocalFileSystem.ItemStoragefindItemStorage(java.lang.String folderPath, java.lang.String itemName)Find an existing storage locationabstract booleanfolderExists(java.lang.String folderPath)Returns true if the folder specified by the path exists.FolderItemgetItem(java.lang.String fileID)Returns the FolderItem specified by its unique File-IDLocalFolderItemgetItem(java.lang.String folderPath, java.lang.String name)Returns the FolderItem in the given folder with the given namejava.lang.String[]getItemNames(java.lang.String folderPath)Returns a list of the folder item names contained in the given folder.protected abstract java.lang.String[]getItemNames(java.lang.String folderPath, boolean includeHiddenFiles)static LocalFileSystemgetLocalFileSystem(java.lang.String rootPath, boolean create, boolean isVersioned, boolean readOnly, boolean enableAsyncronousDispatching)Construct a local filesystem for existing dataabstract intgetMaxNameLength()protected static java.lang.StringgetName(java.lang.String path)protected static java.lang.StringgetParentPath(java.lang.String path)protected static java.lang.StringgetPath(java.lang.String parentPath, java.lang.String name)Returns the full path for a specific folder or itemjava.lang.StringgetUserName()Get user name associated with this filesystem.static booleanisHiddenDirName(java.lang.String name)Determines if the specified storage directory name corresponds to a hidden directory (includes both system and application hidden directories).booleanisOnline()Returns true if file-system is on-line.booleanisReadOnly()Returns true if file-system is read-only.static booleanisRefreshRequired()booleanisShared()Returns true if this file system is sharedstatic booleanisValidNameCharacter(char c)booleanisVersioned()Returns true if the file-system requires check-outs when modifying folder items.protected voiditemDeleted(java.lang.String folderPath, java.lang.String itemName)Notify the filesystem that the property file and associated data files for an item have been removed from the filesystem.protected voidlog(LocalFolderItem item, java.lang.String msg, java.lang.String user)booleanmigrationInProgress()voidmoveItem(java.lang.String folderPath, java.lang.String name, java.lang.String newFolderPath, java.lang.String newName)Moves the specified item to a new folder.voidremoveFileSystemListener(FileSystemListener listener)Removes the listener from being notified of file system changes.voidsetAssociatedRepositoryLogger(RepositoryLogger repositoryLogger)Associate file system with a specific repository loggerstatic voidsetValidationRequired()If set, the state of folder item resources will be continually refreshed.voidtestValidName(java.lang.String name, boolean isPath)Validate a folder/item name or path.static java.lang.StringunescapeHiddenDirPrefixChars(java.lang.String name)Unescape a non-hidden directory name-
Methods 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 Detail
-
HIDDEN_DIR_PREFIX_CHAR
public static final char HIDDEN_DIR_PREFIX_CHAR
Hidden directory name prefix. Should only be prepended to an escaped base-name.- See Also:
#escapeHiddenPrefixChars(String), Constant Field Values
-
HIDDEN_DIR_PREFIX
public static final java.lang.String HIDDEN_DIR_PREFIX
-
HIDDEN_ITEM_PREFIX
public static final java.lang.String HIDDEN_ITEM_PREFIX
Hidden item name prefix.- See Also:
- Constant Field Values
-
root
protected final java.io.File root
-
isVersioned
protected final boolean isVersioned
-
readOnly
protected final boolean readOnly
-
listeners
protected final FileSystemListenerList listeners
-
-
Constructor Detail
-
LocalFileSystem
protected LocalFileSystem(java.lang.String rootPath, boolean isVersioned, boolean readOnly, boolean enableAsyncronousDispatching) throws java.io.FileNotFoundExceptionConstructor.- Parameters:
file- path path for root 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:
java.io.FileNotFoundException- if specified rootPath does not exist
-
LocalFileSystem
protected LocalFileSystem()
Constructor for an empty read-only file-system.
-
-
Method Detail
-
getLocalFileSystem
public static LocalFileSystem getLocalFileSystem(java.lang.String rootPath, boolean create, boolean isVersioned, boolean readOnly, boolean enableAsyncronousDispatching) throws java.io.IOException
Construct a local filesystem for existing data- Parameters:
rootPath-create-isVersioned-readOnly-enableAsyncronousDispatching-- Returns:
- local filesystem
- Throws:
java.io.FileNotFoundException- if specified rootPath does not existjava.io.IOException- if error occurs while reading/writing index files
-
getUserName
public java.lang.String getUserName()
Description copied from interface:FileSystemGet 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:
getUserNamein interfaceFileSystem
-
cleanupAfterConstruction
protected void cleanupAfterConstruction()
-
setAssociatedRepositoryLogger
public void setAssociatedRepositoryLogger(RepositoryLogger repositoryLogger)
Associate file system with a specific repository logger- Parameters:
repositoryLogger-
-
log
protected void log(LocalFolderItem item, java.lang.String msg, java.lang.String user)
-
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).- Parameters:
validationRequired-
-
isRefreshRequired
public static boolean isRefreshRequired()
- See Also:
setValidationRequired()
-
isVersioned
public boolean isVersioned()
Description copied from interface:FileSystemReturns true if the file-system requires check-outs when modifying folder items.- Specified by:
isVersionedin interfaceFileSystem
-
isOnline
public boolean isOnline()
Description copied from interface:FileSystemReturns true if file-system is on-line.- Specified by:
isOnlinein interfaceFileSystem
-
isReadOnly
public boolean isReadOnly()
Description copied from interface:FileSystemReturns true if file-system is read-only.- Specified by:
isReadOnlyin interfaceFileSystem
-
findItemStorage
protected abstract LocalFileSystem.ItemStorage findItemStorage(java.lang.String folderPath, java.lang.String itemName) throws java.io.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:
java.io.FileNotFoundException
-
allocateItemStorage
protected abstract LocalFileSystem.ItemStorage allocateItemStorage(java.lang.String folderPath, java.lang.String itemName) throws java.io.IOException, InvalidNameException
Allocate a new storage location- Parameters:
folderPath-itemName-- Returns:
- storage location
- Throws:
DuplicateFileException- if item path has previously been allocatedjava.io.IOException- if invalid path/item name specifiedInvalidNameException- if folderPath or itemName contains invalid characters
-
deallocateItemStorage
protected abstract void deallocateItemStorage(java.lang.String folderPath, java.lang.String itemName) throws java.io.IOExceptionDeallocate item storage- Parameters:
folderPath-itemName-- Throws:
java.io.IOException
-
getItemNames
protected abstract java.lang.String[] getItemNames(java.lang.String folderPath, boolean includeHiddenFiles) throws java.io.IOException- Throws:
java.io.IOException
-
getItemNames
public java.lang.String[] getItemNames(java.lang.String folderPath) throws java.io.IOExceptionDescription copied from interface:FileSystemReturns a list of the folder item names contained in the given folder.- Specified by:
getItemNamesin interfaceFileSystem- Parameters:
folderPath- the path of the folder.- Returns:
- a list of folder item names.
- Throws:
java.io.IOException- See Also:
FileSystem.getItemNames(java.lang.String)
-
getItem
public LocalFolderItem getItem(java.lang.String folderPath, java.lang.String name) throws java.io.IOException
Description copied from interface:FileSystemReturns the FolderItem in the given folder with the given name- Specified by:
getItemin 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:
java.io.IOException- if IO error occurs.
-
fileIdChanged
protected void fileIdChanged(PropertyFile propertyFile, java.lang.String oldFileId) throws java.io.IOException
Notification that FileID has been changed within propertyFile- Parameters:
propertyFile-oldFileId-- Throws:
java.io.IOException
-
getItem
public FolderItem getItem(java.lang.String fileID) throws java.io.IOException, java.lang.UnsupportedOperationException
Description copied from interface:FileSystemReturns the FolderItem specified by its unique File-ID- Specified by:
getItemin 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:
java.io.IOException- if IO error occurs.java.lang.UnsupportedOperationException- if file-system does not support this operation
-
createDatabase
public LocalDatabaseItem createDatabase(java.lang.String parentPath, java.lang.String name, java.lang.String fileID, BufferFile bufferFile, java.lang.String comment, java.lang.String contentType, boolean resetDatabaseId, TaskMonitor monitor, java.lang.String user) throws InvalidNameException, java.io.IOException, CancelledException
Description copied from interface:FileSystemCreate a new database item within the specified parent folder using the contents of the specified BufferFile.- Specified by:
createDatabasein 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 alphanumericsjava.io.FileNotFoundException- thrown if parent folder does not exist.DuplicateFileException- if a folder item exists with this namejava.io.IOException- if an IO error occurs.CancelledException- if cancelled by monitor
-
createTemporaryDatabase
public LocalDatabaseItem createTemporaryDatabase(java.lang.String parentPath, java.lang.String name, java.lang.String fileID, BufferFile bufferFile, java.lang.String contentType, boolean resetDatabaseId, TaskMonitor monitor) throws InvalidNameException, java.io.IOException, CancelledException
- Throws:
InvalidNameExceptionjava.io.IOExceptionCancelledException
-
createDatabase
public LocalManagedBufferFile createDatabase(java.lang.String parentPath, java.lang.String name, java.lang.String fileID, java.lang.String contentType, int bufferSize, java.lang.String user, java.lang.String projectPath) throws InvalidNameException, java.io.IOException
Description copied from interface:FileSystemCreate 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:
createDatabasein 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 alphanumericsjava.io.FileNotFoundException- thrown if parent folder does not exist.DuplicateFileException- if a folder item exists with this namejava.io.IOException- if an IO error occurs.
-
createDataFile
public LocalDataFile createDataFile(java.lang.String parentPath, java.lang.String name, java.io.InputStream istream, java.lang.String comment, java.lang.String contentType, TaskMonitor monitor) throws InvalidNameException, java.io.IOException, CancelledException
Description copied from interface:FileSystemCreates a new empty data file within the specified parent folder.- Specified by:
createDataFilein interfaceFileSystem- Parameters:
parentPath- folder path of parentname- new data file namecomment- 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 alphanumericsDuplicateFileException- Thrown if a folderItem with that name already exists.java.io.IOException- if an IO error occurs.CancelledException- if cancelled by monitor
-
createFile
public LocalDatabaseItem createFile(java.lang.String parentPath, java.lang.String name, java.io.File packedFile, TaskMonitor monitor, java.lang.String user) throws InvalidNameException, java.io.IOException, CancelledException
Description copied from interface:FileSystemCreates a new file item from a packed file. The content/item type must be determined from the input stream.- Specified by:
createFilein 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 alphanumericsjava.io.IOException- if an IO error occurs.CancelledException- if cancelled by monitor
-
moveItem
public void moveItem(java.lang.String folderPath, java.lang.String name, java.lang.String newFolderPath, java.lang.String newName) throws java.io.IOException, InvalidNameExceptionDescription copied from interface:FileSystemMoves the specified item to a new folder.- Specified by:
moveItemin 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:
java.io.FileNotFoundException- if the item does not exist.DuplicateFileException- if item with the same name exists within the new parent folder.FileInUseException- if the item is in-use or checked-outjava.io.IOException- if an IO error occurs.InvalidNameException- if the newName is invalid
-
folderExists
public abstract boolean folderExists(java.lang.String folderPath)
Description copied from interface:FileSystemReturns true if the folder specified by the path exists.- Specified by:
folderExistsin interfaceFileSystem- Parameters:
folderPath- the name of the folder to check for existence.- Returns:
- true if the folder exists.
-
fileExists
public boolean fileExists(java.lang.String folderPath, java.lang.String name)Description copied from interface:FileSystemReturns true if the file exists- Specified by:
fileExistsin interfaceFileSystem- Parameters:
folderPath- the folderPath of the folder that may contain the file.name- the name of the file to check for existence.
-
addFileSystemListener
public void addFileSystemListener(FileSystemListener listener)
Description copied from interface:FileSystemAdds the given listener to be notified of file system changes.- Specified by:
addFileSystemListenerin interfaceFileSystem- Parameters:
listener- the listener to be added.
-
removeFileSystemListener
public void removeFileSystemListener(FileSystemListener listener)
Description copied from interface:FileSystemRemoves the listener from being notified of file system changes.- Specified by:
removeFileSystemListenerin interfaceFileSystem
-
getMaxNameLength
public abstract int getMaxNameLength()
-
testValidName
public void testValidName(java.lang.String name, boolean isPath) throws InvalidNameExceptionValidate 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
protected void deleteEmptyVersionedFolders(java.lang.String folderPath)
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
protected void itemDeleted(java.lang.String folderPath, java.lang.String itemName) throws java.io.IOExceptionNotify the filesystem that the property file and associated data files for an item have been removed from the filesystem.- Parameters:
folderPath-itemName-- Throws:
java.io.IOException
-
getPath
protected static final java.lang.String getPath(java.lang.String parentPath, java.lang.String name)Returns the full path for a specific folder or item- Parameters:
parentPath- full parent pathname- child folder or item name
-
getParentPath
protected static final java.lang.String getParentPath(java.lang.String path)
-
getName
protected static final java.lang.String getName(java.lang.String path)
-
isShared
public boolean isShared()
Description copied from interface:FileSystemReturns true if this file system is shared- Specified by:
isSharedin interfaceFileSystem
-
dispose
public void dispose()
Description copied from interface:FileSystemCleanup & release resources- Specified by:
disposein interfaceFileSystem
-
migrationInProgress
public boolean migrationInProgress()
-
isHiddenDirName
public static final boolean isHiddenDirName(java.lang.String name)
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
public static final java.lang.String escapeHiddenDirPrefixChars(java.lang.String name)
Escape hidden prefix chars in name- Parameters:
name-- Returns:
- escaped name
-
unescapeHiddenDirPrefixChars
public static final java.lang.String unescapeHiddenDirPrefixChars(java.lang.String name)
Unescape a non-hidden directory name- Parameters:
name-- Returns:
- unescaped name or null if name is a hidden name
-
-