Skip to content

Commit

Permalink
CacheManager.updateCache moves a resource but has an open stream on
Browse files Browse the repository at this point in the history
  • Loading branch information
merks committed Aug 3, 2024
1 parent f5aecaf commit e1b554d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.equinox.p2.discovery.compatibility;singleton:=true
Bundle-Version: 1.3.300.qualifier
Bundle-Version: 1.3.400.qualifier
Bundle-Vendor: %Bundle-Vendor
Bundle-RequiredExecutionEnvironment: JavaSE-17
Require-Bundle: org.eclipse.core.runtime;bundle-version="3.29.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ protected void updateCache(File cacheFile, URI remoteFile, long lastModifiedRemo

tempFile.createNewFile();

IStatus result = null;
try (StatefulStream stream = new StatefulStream(new FileOutputStream(tempFile))) {
IStatus result = null;
try {
submonitor.setWorkRemaining(1000);
result = transport.download(remoteFile, stream, submonitor.newChild(1000));
Expand All @@ -213,21 +213,21 @@ protected void updateCache(File cacheFile, URI remoteFile, long lastModifiedRemo
if (result == null || !result.isOK())
safeDelete(tempFile);
}
if (result.isOK()) {
if (cacheFile.exists())
safeDelete(cacheFile);
if (tempFile.renameTo(cacheFile))
return;
result = new Status(IStatus.ERROR, Activator.ID,
NLS.bind(Messages.CacheManage_ErrorRenamingCache, new Object[] { remoteFile.toString(),
tempFile.getAbsolutePath(), cacheFile.getAbsolutePath() }));
}

if (result.getSeverity() == IStatus.CANCEL || submonitor.isCanceled())
throw new OperationCanceledException();
throw new ProvisionException(result);
} catch (FileNotFoundException e) {
throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, e.getMessage(), e));
}

if (result != null && result.isOK()) {
if (cacheFile.exists())
safeDelete(cacheFile);
if (tempFile.renameTo(cacheFile))
return;
result = new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.CacheManage_ErrorRenamingCache,
new Object[] { remoteFile.toString(), tempFile.getAbsolutePath(), cacheFile.getAbsolutePath() }));
}

if (result != null && result.getSeverity() == IStatus.CANCEL || submonitor.isCanceled())
throw new OperationCanceledException();
throw new ProvisionException(result);
}
}

0 comments on commit e1b554d

Please sign in to comment.