You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "caigy (via GitHub)" <gi...@apache.org> on 2023/05/23 07:59:32 UTC

[GitHub] [rocketmq] caigy commented on a diff in pull request #6778: [ISSUE #6777]Support metric in controller

caigy commented on code in PR #6778:
URL: https://github.com/apache/rocketmq/pull/6778#discussion_r1201632535


##########
common/src/main/java/org/apache/rocketmq/common/UtilAll.java:
##########
@@ -765,4 +765,31 @@ private static void createDirIfNotExist(String dirName) {
             STORE_LOG.info(dirName + " mkdir " + (result ? "OK" : "Failed"));
         }
     }
+
+    public static long calculateFileSizeInPath(File path) {
+        long size = 0;
+        try {
+            if (!path.exists()) {
+                return 0;
+            }
+            if (path.isFile()) {
+                return path.length();
+            }
+            if (path.isDirectory()) {
+                File[] files = path.listFiles();
+                if (files != null) {
+                    for (File file : files) {
+                        long fileSize = 0;
+                        fileSize = calculateFileSizeInPath(file);

Review Comment:
   You'd better check whether the file is a symbolic link before recursion.



##########
controller/pom.xml:
##########
@@ -58,5 +58,9 @@
             <groupId>${project.groupId}</groupId>
             <artifactId>rocketmq-srvutil</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>jul-to-slf4j</artifactId>
+        </dependency>

Review Comment:
   Any reasons to add this dependency?



##########
common/src/main/java/org/apache/rocketmq/common/UtilAll.java:
##########
@@ -765,4 +765,31 @@ private static void createDirIfNotExist(String dirName) {
             STORE_LOG.info(dirName + " mkdir " + (result ? "OK" : "Failed"));
         }
     }
+
+    public static long calculateFileSizeInPath(File path) {
+        long size = 0;
+        try {
+            if (!path.exists()) {
+                return 0;
+            }
+            if (path.isFile()) {
+                return path.length();
+            }
+            if (path.isDirectory()) {
+                File[] files = path.listFiles();
+                if (files != null) {
+                    for (File file : files) {
+                        long fileSize = 0;
+                        fileSize = calculateFileSizeInPath(file);

Review Comment:
   It's unnecessary to initialize `fileSize` as 0 as it's assigned right after initialization.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org