This is an automated email from the ASF dual-hosted git repository.
aloyszhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git
The following commit(s) were added to refs/heads/master by this push:
new a843dc806a [INLONG-11556][Agent] Resolve exceptions when saving
installation packages (#11557)
a843dc806a is described below
commit a843dc806a33e65d89006c502f25fe28f7df4197
Author: justinwwhuang <[email protected]>
AuthorDate: Mon Dec 2 14:05:40 2024 +0800
[INLONG-11556][Agent] Resolve exceptions when saving installation packages
(#11557)
---
.../inlong/agent/installer/ModuleManager.java | 25 +++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git
a/inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java
b/inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java
index de05a9d0f7..cae8b25f68 100755
---
a/inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java
+++
b/inlong-agent/agent-installer/src/main/java/org/apache/inlong/agent/installer/ModuleManager.java
@@ -551,8 +551,17 @@ public class ModuleManager extends AbstractDaemon {
authHeader.forEach((k, v) -> {
conn.setRequestProperty(k, v);
});
- String path =
- module.getPackageConfig().getStoragePath() + "/" +
module.getPackageConfig().getFileName();
+ String saveFolder =
getRealPath(module.getPackageConfig().getStoragePath());
+ File folder = new File(saveFolder);
+ if (!folder.exists()) {
+ boolean folderCreated = folder.mkdirs();
+ if (folderCreated) {
+ LOGGER.info("saveFolder {} created", saveFolder);
+ } else {
+ LOGGER.error("failed to create saveFolder {}", saveFolder);
+ }
+ }
+ String path = saveFolder + "/" +
module.getPackageConfig().getFileName();
try (InputStream inputStream = conn.getInputStream();
FileOutputStream outputStream = new
FileOutputStream(path)) {
LOGGER.info("module {}({}) save path {}", module.getId(),
module.getName(), path);
@@ -578,7 +587,8 @@ public class ModuleManager extends AbstractDaemon {
}
private boolean isPackageDownloaded(ModuleConfig module) {
- String path = module.getPackageConfig().getStoragePath() + "/" +
module.getPackageConfig().getFileName();
+ String path =
+ getRealPath(module.getPackageConfig().getStoragePath()) + "/"
+ module.getPackageConfig().getFileName();
String fileMd5 = calcFileMd5(path);
if (Objects.equals(fileMd5, module.getPackageConfig().getMd5())) {
return true;
@@ -589,6 +599,15 @@ public class ModuleManager extends AbstractDaemon {
}
}
+ private String getRealPath(String originPath) {
+ String homeDir = System.getProperty("user.home");
+ if (homeDir == null) {
+ LOGGER.warn("user.home should not be null");
+ return originPath;
+ }
+ return originPath.replace("~", homeDir).replace("${HOME}",
homeDir).replace("${home}", homeDir);
+ }
+
@Override
public void start() throws Exception {
httpManager = getHttpManager(conf);