Skip to content

Commit

Permalink
Avoid piling up FileListener during GC
Browse files Browse the repository at this point in the history
This short-cuts getting the URIs for Collected files.
DarcBasicTest.testCollectBlobs ensures result is unchanged.
  • Loading branch information
ecki committed May 24, 2024
1 parent dc90645 commit 3446144
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,26 @@ public DarcFileCollectOperation(FileObject root)
public void process()
throws FileSystemException
{
if (root instanceof DarcFileObject)
if (!(root instanceof DarcFileObject))
{
DarcFileObject darcFile = (DarcFileObject) root;
FileObject delegateFile = darcFile.getDelegateFile();
return;
}

filesList.add(delegateFile.getName().getURI());
final DarcFileObject darcFile = (DarcFileObject) root;
final String uri = darcFile.getDelegateURI();
filesList.add(uri);

if (darcFile.getType() == FileType.FOLDER)
if (darcFile.getType() == FileType.FOLDER)
{
FileObject[] fileList = darcFile.getChildren();
for (FileObject nextFile : fileList)
{
FileObject[] fileList = darcFile.getChildren();
for (FileObject nextFile : fileList)
FileOperations fileOperations = nextFile.getFileOperations();
CollectFilesOperation operation = (CollectFilesOperation) fileOperations.getOperation(CollectFilesOperation.class);
if (operation != null)
{
FileOperations fileOperations = nextFile.getFileOperations();
CollectFilesOperation operation = (CollectFilesOperation) fileOperations.getOperation(CollectFilesOperation.class);
if (operation != null)
{
operation.setFilesList(filesList);
operation.process();
}
operation.setFilesList(filesList);
operation.process();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,28 @@ public void fileChanged(FileChangeEvent event)
}
}


/**
* Used by DarcFileCollectOperation to get URI of delegate.
* <P>
* This is done to avoid listener registration in {@link #getDelegateFile()}.
*
* @throws FileSystemException if lower level miss-behaves
*/
protected String getDelegateURI() throws FileSystemException
{
Entry entry = getEntry();
String hash = entry.getHash();
FileObject targetFile = getProvider().resolveFileHash(hash);
if (targetFile != null)
{
/* we could refresh target here */
return targetFile.getName().getURI();
}
throw new FileSystemException("Expected file blob with hash=" + hash + " cannot be resolved");
}


private BlobStorageProvider getProvider()
{
return ((DarcFileSystem)getFileSystem()).getBlobProvider();
Expand Down

0 comments on commit 3446144

Please sign in to comment.