public boolean download(String siaPath, Path destination) {
LOGGER.info("downloading {}", siaPath);
// final String dest = destination.toAbsolutePath().toString();
final FileTime lastModified = SiaFileUtil.getFileTime(siaPath);
final String tempFileName = destination.getFileName().toString() + ".tempdownload";
Path tempFile = destination.getParent().resolve(tempFileName);
final HttpResponse<String> downloadResult = siaCommand(SiaCommand.DOWNLOAD, ImmutableMap.of("destination", tempFile.toAbsolutePath().toString()), siaPath);
final boolean noHosts = checkErrorFragment(downloadResult, NO_HOSTS);
if (noHosts) {
LOGGER.warn("unable to download file {} due to NO_HOSTS ", siaPath);
return false;
}
if (statusGood(downloadResult)) {
try {
Files.setLastModifiedTime(tempFile, lastModified);
Files.move(tempFile, destination, StandardCopyOption.ATOMIC_MOVE);
Files.setLastModifiedTime(destination, lastModified);
} catch (IOException e) {
throw new RuntimeException("unable to do atomic swap of file " + destination);
}
return true;
}
LOGGER.warn("unable to download siaPath {} for an unexpected reason: {} ", siaPath, downloadResult.getBody());
return false;
}
SiaUtil.java 文件源码
java
阅读 32
收藏 0
点赞 0
评论 0
项目:minebox
作者:
评论列表
文章目录