Merge remote-tracking branch

'origin/GP-2552_dev747368_retry_pdb_downloads--SQUASHED' (Closes #4324)
This commit is contained in:
Ryan Kurtz
2022-09-20 01:09:17 -04:00

View File

@@ -43,6 +43,7 @@ import pdb.PdbUtils;
*/ */
public class SymbolServerService { public class SymbolServerService {
private static final int MAX_TRY_COUNT = 3;
private SymbolStore symbolStore; // also the first element of the symbolServers list private SymbolStore symbolStore; // also the first element of the symbolServers list
private List<SymbolServer> symbolServers; private List<SymbolServer> symbolServers;
@@ -234,20 +235,7 @@ public class SymbolServerService {
private SymbolFileLocation ensureLocalUncompressedFile(SymbolFileLocation symbolFileLocation, private SymbolFileLocation ensureLocalUncompressedFile(SymbolFileLocation symbolFileLocation,
TaskMonitor monitor) throws IOException, CancelledException { TaskMonitor monitor) throws IOException, CancelledException {
if (!(symbolFileLocation.getSymbolServer() instanceof SymbolStore)) { if (!(symbolFileLocation.getSymbolServer() instanceof SymbolStore)) {
Msg.debug(this, logPrefix() + ": copying file " + symbolFileLocation.getLocationStr() + symbolFileLocation = copyRemoteToLocal(symbolFileLocation, monitor);
" from remote to local " + symbolStore.getName());
// copy from remote store to our main local symbol store
String remoteFilename = FilenameUtils.getName(symbolFileLocation.getPath());
try (SymbolServerInputStream symbolServerInputStream =
symbolFileLocation.getSymbolServer()
.getFileStream(symbolFileLocation.getPath(), monitor)) {
String newPath =
symbolStore.putStream(symbolFileLocation.getFileInfo(), symbolServerInputStream,
remoteFilename, monitor);
symbolFileLocation =
new SymbolFileLocation(newPath, symbolStore, symbolFileLocation.getFileInfo());
}
} }
// symbolFileLocation now must be on a SymbolStore, so safe to cast // symbolFileLocation now must be on a SymbolStore, so safe to cast
@@ -263,8 +251,8 @@ public class SymbolServerService {
File temporaryExtractFile = File temporaryExtractFile =
new File(adminDir, "ghidra_cab_extract_tmp_" + System.currentTimeMillis()); new File(adminDir, "ghidra_cab_extract_tmp_" + System.currentTimeMillis());
Msg.debug(this, Msg.debug(this, "%s: decompressing file %s".formatted(logPrefix(),
logPrefix() + ": decompressing file " + symbolFileLocation.getLocationStr()); symbolFileLocation.getLocationStr()));
String originalName = String originalName =
PdbUtils.extractSingletonCabToFile(cabFile, temporaryExtractFile, monitor); PdbUtils.extractSingletonCabToFile(cabFile, temporaryExtractFile, monitor);
@@ -275,13 +263,45 @@ public class SymbolServerService {
symbolFileLocation = new SymbolFileLocation(uncompressedPath, symbolStore, symbolFileLocation = new SymbolFileLocation(uncompressedPath, symbolStore,
symbolFileLocation.getFileInfo()); symbolFileLocation.getFileInfo());
Msg.debug(this, Msg.debug(this, "%s: new decompressed file %s".formatted(logPrefix(),
logPrefix() + ": new decompressed file " + symbolFileLocation.getLocationStr()); symbolFileLocation.getLocationStr()));
} }
return symbolFileLocation; return symbolFileLocation;
} }
private SymbolFileLocation copyRemoteToLocal(SymbolFileLocation symbolFileLocation,
TaskMonitor monitor) throws CancelledException, IOException {
int tryCount = 0;
while (true) {
Msg.debug(this,
"%s try[%d]: copying file %s from remote to local %s".formatted(logPrefix(),
tryCount, symbolFileLocation.getLocationStr(), symbolStore.getName()));
// copy from remote store to our main local symbol store
String remoteFilename = FilenameUtils.getName(symbolFileLocation.getPath());
try (SymbolServerInputStream symbolServerInputStream =
symbolFileLocation.getSymbolServer()
.getFileStream(symbolFileLocation.getPath(), monitor)) {
String newPath = symbolStore.putStream(symbolFileLocation.getFileInfo(),
symbolServerInputStream, remoteFilename, monitor);
return new SymbolFileLocation(newPath, symbolStore,
symbolFileLocation.getFileInfo());
}
catch (IOException e) {
String msg = "%s: error copying file %s to %s: %s".formatted(logPrefix(),
symbolFileLocation.getLocationStr(), symbolStore.getName(), e.getMessage());
if (++tryCount >= MAX_TRY_COUNT) {
Msg.error(this, msg);
throw e; // failure
}
// allow retry
Msg.warn(this, msg);
}
}
}
private String logPrefix() { private String logPrefix() {
return getClass().getSimpleName(); return getClass().getSimpleName();
} }