This is an automated email from the ASF dual-hosted git repository.

dockerzhang 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 5b559ee139 [INLONG-9987][Agent] Fix the issue of deleting the first 
digit when the first digit in MD5 is 0 (#9988)
5b559ee139 is described below

commit 5b559ee1399e74030be3676064c17891414e2944
Author: justinwwhuang <[email protected]>
AuthorDate: Mon Apr 15 16:08:41 2024 +0800

    [INLONG-9987][Agent] Fix the issue of deleting the first digit when the 
first digit in MD5 is 0 (#9988)
---
 .../java/org/apache/inlong/agent/installer/ModuleManager.java | 11 +++++------
 1 file changed, 5 insertions(+), 6 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 031057bb48..4e95703360 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
@@ -33,6 +33,7 @@ import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonParser;
+import org.apache.commons.codec.binary.Hex;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -46,7 +47,6 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 import java.io.Reader;
-import java.math.BigInteger;
 import java.net.URL;
 import java.net.URLConnection;
 import java.nio.charset.StandardCharsets;
@@ -445,9 +445,11 @@ public class ModuleManager extends AbstractDaemon {
 
     private boolean isPackageDownloaded(ModuleConfig module) {
         String path = module.getPackageConfig().getStoragePath() + "/" + 
module.getPackageConfig().getFileName();
-        if (calcFileMd5(path).equals(module.getPackageConfig().getMd5())) {
+        String fileMd5 = calcFileMd5(path);
+        if (fileMd5.equals(module.getPackageConfig().getMd5())) {
             return true;
         } else {
+            LOGGER.error("md5 not match! fileMd5 {} moduleMd5 {}", fileMd5, 
module.getPackageConfig().getMd5());
             return false;
         }
     }
@@ -474,7 +476,6 @@ public class ModuleManager extends AbstractDaemon {
     }
 
     private static String calcFileMd5(String path) {
-        BigInteger bi = null;
         byte[] buffer = new byte[DOWNLOAD_PACKAGE_READ_BUFF_SIZE];
         int len = 0;
         try (FileInputStream fileInputStream = new FileInputStream(path)) {
@@ -482,8 +483,7 @@ public class ModuleManager extends AbstractDaemon {
             while ((len = fileInputStream.read(buffer)) != -1) {
                 md.update(buffer, 0, len);
             }
-            byte[] b = md.digest();
-            bi = new BigInteger(1, b);
+            return new String(Hex.encodeHex(md.digest()));
         } catch (NoSuchAlgorithmException e) {
             LOGGER.error("calc file md5 NoSuchAlgorithmException", e);
             return "";
@@ -491,6 +491,5 @@ public class ModuleManager extends AbstractDaemon {
             LOGGER.error("calc file md5 IOException", e);
             return "";
         }
-        return bi.toString(16);
     }
 }

Reply via email to