You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/10/11 08:15:46 UTC

[GitHub] [incubator-seatunnel] CalvinKirs commented on a diff in pull request #3038: [E2E][ST-Engine] Add test data consistency in 3 node cluster and fix bug

CalvinKirs commented on code in PR #3038:
URL: https://github.com/apache/incubator-seatunnel/pull/3038#discussion_r991989214


##########
seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/FileUtils.java:
##########
@@ -79,4 +82,76 @@ public static void createNewFile(String filePath) {
             createParentFile(file);
         }
     }
+
+    /**
+     * return the line number of file
+     *
+     * @param filePath The file need be read
+     * @return
+     */
+    public static Long getFileLineNumber(@NonNull String filePath) {
+        try {
+            return Files.lines(Paths.get(filePath)).count();
+        } catch (IOException e) {
+            throw new SeaTunnelException(String.format("get file[%s] line error", filePath), e);
+        }
+    }
+
+    /**
+     * return the line number of all files in the dirPath
+     *
+     * @param dirPath dirPath
+     * @return
+     */
+    public static Long getFileLineNumberFromDir(@NonNull String dirPath) {
+        File file = new File(dirPath);
+        Long value = null;
+        if (file.isDirectory()) {
+            value = Arrays.stream(file.listFiles()).map(currFile -> {
+                if (currFile.isDirectory()) {
+                    return getFileLineNumberFromDir(currFile.getPath());
+                } else {
+                    return getFileLineNumber(currFile.getPath());
+                }
+            }).mapToLong(Long::longValue).sum();
+        } else {
+            value = getFileLineNumber(file.getPath());
+        }
+
+        return value;
+    }
+
+    /**
+     * clear dir and the sub dir
+     *
+     * @param filePath filePath
+     * @return
+     */
+    public static void deleteFile(@NonNull String filePath) {
+        File file = new File(filePath);
+        if (file.exists()) {
+            if (file.isDirectory()) {
+                deleteFiles(file);
+            }
+            file.delete();

Review Comment:
   Here it may fail, we'd better add the corresponding judgment, if it fails, print the corresponding log (if the failure result is not so important)



-- 
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@seatunnel.apache.org

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