Ghidra is a software reverse engineering (SRE) framework
GP-4455 Changed RemoteFileItem to cache FileID
ghidra1b8cc7abea166
diff --git a/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/remote/RepositoryItem.java b/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/remote/RepositoryItem.javaindex 6b02a52d2b..830a8910b1 100644--- a/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/remote/RepositoryItem.java+++ b/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/remote/RepositoryItem.java@@ -48,6 +48,7 @@ public class RepositoryItem implements java.io.Serializable {* Constructor.* @param folderPath path of folder containing item.* @param itemName name of item+ * @param fileID unique file ID* @param itemType type of item (FILE or DATABASE)* @param contentType content type associated with item* @param version repository item version or -1 if versioning not supported@@ -66,8 +67,8 @@ public class RepositoryItem implements java.io.Serializable {/*** Serialization method- * @param out- * @throws IOException+ * @param out serialization output stream+ * @throws IOException if an IO error occurs*/private void writeObject(java.io.ObjectOutputStream out) throws IOException {out.writeLong(serialVersionUID);@@ -82,9 +83,9 @@ public class RepositoryItem implements java.io.Serializable {/*** Deserialization method- * @param in- * @throws IOException- * @throws ClassNotFoundException+ * @param in deserialization input stream+ * @throws IOException if IO error occurs+ * @throws ClassNotFoundException if unrecognized serialVersionUID detected*/private void readObject(java.io.ObjectInputStream in) throws IOException,ClassNotFoundException {diff --git a/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/store/remote/RemoteDatabaseItem.java b/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/store/remote/RemoteDatabaseItem.javaindex 79333fc27c..35dee3cb6d 100644--- a/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/store/remote/RemoteDatabaseItem.java+++ b/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/store/remote/RemoteDatabaseItem.java@@ -57,13 +57,13 @@ public class RemoteDatabaseItem extends RemoteFolderItem implements DatabaseItem}@Override- public ManagedBufferFileAdapter open(int version, int minChangeDataVer) throws IOException {- return repository.openDatabase(parentPath, itemName, version, minChangeDataVer);+ public ManagedBufferFileAdapter open(int fileVersion, int minChangeDataVer) throws IOException {+ return repository.openDatabase(parentPath, itemName, fileVersion, minChangeDataVer);}@Override- public ManagedBufferFileAdapter open(int version) throws IOException {- return repository.openDatabase(parentPath, itemName, version, -1);+ public ManagedBufferFileAdapter open(int fileVersion) throws IOException {+ return repository.openDatabase(parentPath, itemName, fileVersion, -1);}@Override@@ -82,9 +82,6 @@ public class RemoteDatabaseItem extends RemoteFolderItem implements DatabaseItemrepository.updateCheckoutVersion(parentPath, itemName, checkoutId, checkoutVersion);}- /*- * @see ghidra.framework.store.FolderItem#hasCheckouts()- */@Overridepublic boolean hasCheckouts() throws IOException {return repository.hasCheckouts(parentPath, itemName);@@ -96,10 +93,10 @@ public class RemoteDatabaseItem extends RemoteFolderItem implements DatabaseItem}@Override- public void output(File outputFile, int version, TaskMonitor monitor)+ public void output(File outputFile, int fileVersion, TaskMonitor monitor)throws IOException, CancelledException {- BufferFile bf = repository.openDatabase(parentPath, itemName, version, -1);+ BufferFile bf = repository.openDatabase(parentPath, itemName, fileVersion, -1);try {File tmpFile = File.createTempFile("ghidra", LocalBufferFile.TEMP_FILE_EXT);tmpFile.delete();@@ -108,18 +105,10 @@ public class RemoteDatabaseItem extends RemoteFolderItem implements DatabaseItemLocalBufferFile.copyFile(bf, tmpBf, null, monitor);tmpBf.close();- InputStream itemIn = new FileInputStream(tmpFile);- try {+ try (InputStream itemIn = new FileInputStream(tmpFile)) {ItemSerializer.outputItem(getName(), getContentType(), DATABASE_FILE_TYPE,tmpFile.length(), itemIn, outputFile, monitor);}- finally {- try {- itemIn.close();- }- catch (IOException e) {- }- }}finally {tmpBf.close();diff --git a/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/store/remote/RemoteFolderItem.java b/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/store/remote/RemoteFolderItem.javaindex 9f2ac52f99..b027f3f401 100644--- a/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/store/remote/RemoteFolderItem.java+++ b/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/store/remote/RemoteFolderItem.java@@ -27,9 +27,11 @@ import ghidra.framework.store.*;*/public abstract class RemoteFolderItem implements FolderItem {- protected String parentPath;- protected String itemName;- protected String contentType;+ protected final String parentPath;+ protected final String itemName;+ protected final String contentType;+ protected final String fileID;+protected int version;protected long versionTime;@@ -45,26 +47,26 @@ public abstract class RemoteFolderItem implements FolderItem {parentPath = item.getParentPath();itemName = item.getName();contentType = item.getContentType();+ fileID = item.getFileID();+version = item.getVersion();versionTime = item.getVersionTime();}/**- * Returns the item type as defined by RepositoryItem.+ * Returns the item type as defined by RepositoryItem which corresponds to specific+ * implementation of this class.+ * @return item type (Only {@link RepositoryItem#DATABASE} is supported).* @see ghidra.framework.remote.RepositoryItem*/abstract int getItemType();- /*- * @see ghidra.framework.store.FolderItem#getName()- */+ @Overridepublic String getName() {return itemName;}- /*- * @see ghidra.framework.store.FolderItem#refresh()- */+ @Overridepublic RemoteFolderItem refresh() throws IOException {RepositoryItem item = repository.getItem(parentPath, itemName);if (item == null) {@@ -75,42 +77,27 @@ public abstract class RemoteFolderItem implements FolderItem {return this;}- /**- * @throws IOException- * @see ghidra.framework.store.FolderItem#getFileID()- */- public String getFileID() throws IOException {- RepositoryItem item = repository.getItem(parentPath, itemName);- if (item != null) {- return item.getFileID();- }- return null;+ @Override+ public String getFileID() {+ return fileID;}- /**- * @see ghidra.framework.store.FolderItem#resetFileID()- */+ @Overridepublic String resetFileID() {throw new UnsupportedOperationException();}- /*- * @see ghidra.framework.store.FolderItem#getContentType()- */+ @Overridepublic String getContentType() {return contentType;}- /*- * @see ghidra.framework.store.FolderItem#getParentPath()- */+ @Overridepublic String getParentPath() {return parentPath;}- /*- * @see ghidra.framework.store.FolderItem#getPathName()- */+ @Overridepublic String getPathName() {String path = parentPath;if (path.length() != 1) {@@ -119,149 +106,110 @@ public abstract class RemoteFolderItem implements FolderItem {return path + itemName;}- /*- * @see ghidra.framework.store.FolderItem#isReadOnly()- */+ @Overridepublic boolean isReadOnly() {throw new UnsupportedOperationException("isReadOnly is not applicable to versioned item");}- /*- * @see ghidra.framework.store.FolderItem#setReadOnly(boolean)- */+ @Overridepublic void setReadOnly(boolean state) {throw new UnsupportedOperationException("setReadOnly is not applicable to versioned item");}- /**- * Returns the version of content type. Note this is the version of the structure/storage- * for the content type, Not the users version of their data.- */+ @Overridepublic int getContentTypeVersion() {throw new UnsupportedOperationException("getContentTypeVersion is not applicable to versioned item");}- /**- * @see ghidra.framework.store.FolderItem#setContentTypeVersion(int)- */+ @Overridepublic void setContentTypeVersion(int version) throws IOException {throw new UnsupportedOperationException("setContentTypeVersion is not applicable to versioned item");}- /*- * @see ghidra.framework.store.FolderItem#lastModified()- */+ @Overridepublic long lastModified() {return versionTime;}- /*- * @see ghidra.framework.store.FolderItem#getCurrentVersion()- */+ @Overridepublic int getCurrentVersion() {return version;}- /*- * @see ghidra.framework.store.FolderItem#isVersioned()- */+ @Overridepublic boolean isVersioned() {return (version != -1);}- /*- * @see ghidra.framework.store.FolderItem#getVersions()- */+ @Overridepublic Version[] getVersions() throws IOException {return repository.getVersions(parentPath, itemName);}- /*- * @see ghidra.framework.store.FolderItem#delete(int, java.lang.String)- */+ @Overridepublic void delete(int ver, String user) throws IOException {repository.deleteItem(parentPath, itemName, ver);}- /*- * @see ghidra.framework.store.FolderItem#isPrivate()- */+ @Overridepublic boolean isCheckedOut() {throw new UnsupportedOperationException("isCheckedOut is not applicable to versioned item");}- /*- * @see ghidra.framework.store.FolderItem#isCheckedOutExclusive()- */+ @Overridepublic boolean isCheckedOutExclusive() {throw new UnsupportedOperationException("isCheckedOutExclusive is not applicable to versioned item");}- /*- * @see ghidra.framework.store.FolderItem#checkout(boolean, java.lang.String, java.lang.String)- */+ @Overridepublic ItemCheckoutStatus checkout(CheckoutType checkoutType, String user, String projectPath)throws IOException {return repository.checkout(parentPath, itemName, checkoutType, projectPath);}- /*- * @see ghidra.framework.store.FolderItem#terminateCheckout(long, boolean)- */+ @Overridepublic void terminateCheckout(long checkoutId, boolean notify) throws IOException {repository.terminateCheckout(parentPath, itemName, checkoutId, notify);}- /*- * @see ghidra.framework.store.FolderItem#getCheckout(long)- */+ @Overridepublic ItemCheckoutStatus getCheckout(long checkoutId) throws IOException {return repository.getCheckout(parentPath, itemName, checkoutId);}- /*- * @see ghidra.framework.store.FolderItem#getCheckouts()- */+ @Overridepublic ItemCheckoutStatus[] getCheckouts() throws IOException {return repository.getCheckouts(parentPath, itemName);}- /*- * @see ghidra.framework.store.FolderItem#clearCheckout()- */+ @Overridepublic void clearCheckout() throws IOException {- throw new UnsupportedOperationException("clearCheckout is not applicable to versioned item");+ throw new UnsupportedOperationException(+ "clearCheckout is not applicable to versioned item");}- /*- * @see ghidra.framework.store.FolderItem#getCheckoutId()- */+ @Overridepublic long getCheckoutId() throws IOException {- throw new UnsupportedOperationException("getCheckoutId is not applicable to versioned item");+ throw new UnsupportedOperationException(+ "getCheckoutId is not applicable to versioned item");}- /*- * @see ghidra.framework.store.FolderItem#getCheckoutVersion()- */+ @Overridepublic int getCheckoutVersion() throws IOException {throw new UnsupportedOperationException("getCheckoutVersion is not applicable to versioned item");}- /*- * @see ghidra.framework.store.FolderItem#getLocalCheckoutVersion()- */+ @Overridepublic int getLocalCheckoutVersion() {throw new UnsupportedOperationException("getLocalCheckoutVersion is not applicable to versioned item");}- /*- * @see ghidra.framework.store.FolderItem#setCheckout(long, boolean, int, int)- */+ @Overridepublic void setCheckout(long checkoutId, boolean exclusive, int checkoutVersion,int localVersion) throws IOException {throw new UnsupportedOperationException("setCheckout is not applicable to versioned item");