You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/06/30 14:55:49 UTC

[GitHub] [dolphinscheduler] sketchmind commented on a diff in pull request #10675: [Fix-10665] [S3] Fix s3 download method

sketchmind commented on code in PR #10675:
URL: https://github.com/apache/dolphinscheduler/pull/10675#discussion_r911129734


##########
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/S3Utils.java:
##########
@@ -175,21 +175,36 @@ public String getFileName(ResourceType resourceType, String tenantCode, String f
     }
 
     @Override
-    public void download(String tenantCode, String srcFilePath, String dstFile, boolean deleteSource, boolean overwrite) throws IOException {
+    public void download(String tenantCode, String srcFilePath, String dstFilePath, boolean deleteSource, boolean overwrite) throws IOException {
+        File dstFile = new File(dstFilePath);
+        File dstFileParentDirectory = dstFile.getParentFile();
+        if (dstFile.exists()) {
+            if (dstFile.isDirectory()) {
+                logger.error("destination file must be a file, but {} is a folder", dstFilePath);
+                throw new IOException("destination file must be a file, but " + dstFilePath +" is a folder");
+            } else if (!overwrite) {
+                logger.info("the destination file {} already exists, download operation will be ignored", dstFilePath);
+                return;
+            }
+        } else {
+            if (!dstFileParentDirectory.mkdirs() && !dstFileParentDirectory.exists()) {
+                throw new IOException("failed to create parent directory of destination file, directory is " + dstFileParentDirectory.getAbsolutePath());
+            }

Review Comment:
   * If the failed to create dir exception is not thrown in time, it will unnecessarily request s3 resources
   * I will replaced it with FileUtils on next push



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

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