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

pvillard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new ec3d5f8  NIFI-8086: Fix file separator char in PutS3Object multipart 
state directory path
ec3d5f8 is described below

commit ec3d5f89f08c4b6730e2c3413d48e40800b2d7d1
Author: Peter Turcsanyi <[email protected]>
AuthorDate: Sat Dec 12 17:24:33 2020 +0100

    NIFI-8086: Fix file separator char in PutS3Object multipart state directory 
path
    
    Signed-off-by: Pierre Villard <[email protected]>
    
    This closes #4726.
---
 .../apache/nifi/processors/aws/s3/PutS3Object.java |  2 +-
 .../nifi/processors/aws/s3/TestPutS3Object.java    | 38 +++++++++++++++++++++-
 2 files changed, 38 insertions(+), 2 deletions(-)

diff --git 
a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/main/java/org/apache/nifi/processors/aws/s3/PutS3Object.java
 
b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/main/java/org/apache/nifi/processors/aws/s3/PutS3Object.java
index 55cdfb9..0fed5ee 100644
--- 
a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/main/java/org/apache/nifi/processors/aws/s3/PutS3Object.java
+++ 
b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/main/java/org/apache/nifi/processors/aws/s3/PutS3Object.java
@@ -317,7 +317,7 @@ public class PutS3Object extends AbstractS3Processor {
     }
 
     protected File getPersistenceFile() {
-        return new File(this.tempDirMultipart + File.pathSeparator + 
getIdentifier());
+        return new File(this.tempDirMultipart + File.separator + 
getIdentifier());
     }
 
     protected boolean localUploadExistsInS3(final AmazonS3Client s3, final 
String bucket, final MultipartState localState) {
diff --git 
a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestPutS3Object.java
 
b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestPutS3Object.java
index fad50b1..4fc2440 100644
--- 
a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestPutS3Object.java
+++ 
b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestPutS3Object.java
@@ -16,6 +16,7 @@
  */
 package org.apache.nifi.processors.aws.s3;
 
+import java.io.File;
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.util.Date;
@@ -25,6 +26,7 @@ import java.util.Map;
 
 import com.amazonaws.services.s3.model.StorageClass;
 import com.amazonaws.services.s3.model.Tag;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.nifi.components.AllowableValue;
 import org.apache.nifi.components.PropertyDescriptor;
 import org.apache.nifi.flowfile.attributes.CoreAttributes;
@@ -70,7 +72,9 @@ public class TestPutS3Object {
             }
         };
         runner = TestRunners.newTestRunner(putS3Object);
-        runner.setVariable("java.io.tmpdir", "conf/state");
+
+        // MockPropertyValue does not evaluate system properties, set it in a 
variable with the same name
+        runner.setVariable("java.io.tmpdir", 
System.getProperty("java.io.tmpdir"));
     }
 
     @Test
@@ -208,6 +212,38 @@ public class TestPutS3Object {
     }
 
     @Test
+    public void testPersistenceFileLocationWithDefaultTempDir() {
+        String dir = System.getProperty("java.io.tmpdir");
+
+        executePersistenceFileLocationTest(StringUtils.appendIfMissing(dir, 
File.separator) + putS3Object.getIdentifier());
+    }
+
+    @Test
+    public void 
testPersistenceFileLocationWithUserDefinedDirWithEndingSeparator() {
+        String dir = StringUtils.appendIfMissing(new 
File("target").getAbsolutePath(), File.separator);
+        runner.setProperty(PutS3Object.MULTIPART_TEMP_DIR, dir);
+
+        executePersistenceFileLocationTest(dir + putS3Object.getIdentifier());
+    }
+
+    @Test
+    public void 
testPersistenceFileLocationWithUserDefinedDirWithoutEndingSeparator() {
+        String dir = StringUtils.removeEnd(new 
File("target").getAbsolutePath(), File.separator);
+        runner.setProperty(PutS3Object.MULTIPART_TEMP_DIR, dir);
+
+        executePersistenceFileLocationTest(dir + File.separator + 
putS3Object.getIdentifier());
+    }
+
+    private void executePersistenceFileLocationTest(String expectedPath) {
+        prepareTest();
+
+        runner.run(1);
+        File file = putS3Object.getPersistenceFile();
+
+        assertEquals(expectedPath, file.getAbsolutePath());
+    }
+
+    @Test
     public void testGetPropertyDescriptors() {
         PutS3Object processor = new PutS3Object();
         List<PropertyDescriptor> pd = 
processor.getSupportedPropertyDescriptors();

Reply via email to