MuazmaZ commented on a change in pull request #5098:
URL: https://github.com/apache/nifi/pull/5098#discussion_r648759607



##########
File path: 
nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/processors/azure/storage/utils/AzureTempFilePrefixValidator.java
##########
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.azure.storage.utils;
+
+import org.apache.nifi.components.PropertyValue;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.components.Validator;
+
+import java.util.regex.Pattern;
+
+public class AzureTempFilePrefixValidator implements Validator {
+    private static final Pattern TEMP_FILE_PREFIX_PATTERN = 
Pattern.compile("^[^\"\\\\/:|<>*?]*$");
+
+    @Override
+    public ValidationResult validate(String subject, String input, 
ValidationContext context) {
+        PropertyValue prefixProperty = context.newPropertyValue(input);
+        final String prefix;
+        if (prefixProperty.isExpressionLanguagePresent()) {
+            try {
+                prefix = 
prefixProperty.evaluateAttributeExpressions().getValue();
+            } catch (final Exception e) {
+                return new ValidationResult.Builder()
+                        .subject(subject)
+                        .input(input)
+                        .valid(false)
+                        .explanation("Failed to evaluate the Attribute 
Expression Language due to " + e.toString())
+                        .build();
+            }
+        } else {
+            prefix = prefixProperty.getValue();
+        }
+
+        if (TEMP_FILE_PREFIX_PATTERN.matcher(prefix).matches()) {
+            return new ValidationResult.Builder()
+                    .subject(subject)
+                    .input(prefix)
+                    .valid(true)
+                    .build();
+        } else {
+            return new ValidationResult.Builder()
+                    .subject(subject)
+                    .input(prefix)
+                    .valid(false)
+                    .explanation("Prefix cannot contain \" / \\ < > : | * ? 
characters.")
+                    .build();
+        }
+    }
+}

Review comment:
       In addition to this validation, a possible validation could be: The 
following file names are not allowed: LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, 
LPT8, LPT9, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, PRN, AUX, 
NUL, CON, CLOCK$, dot character (.), and two-dot characters (..).

##########
File path: 
nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/processors/azure/storage/PutAzureDataLakeStorage.java
##########
@@ -192,4 +211,29 @@ static void uploadContent(DataLakeFileClient fileClient, 
InputStream in, long le
 
         fileClient.flush(length);
     }
+
+    private DataLakeFileClient renameFile(String fileName, String 
directoryPath, DataLakeFileClient fileClient, boolean overwrite) {
+        try {
+            final DataLakeRequestConditions destinationCondition = new 
DataLakeRequestConditions();
+            if (!overwrite) {
+                destinationCondition.setIfNoneMatch("*");
+            }
+            String destinationPath = StringUtils.isNotEmpty(directoryPath)
+                    ? directoryPath + "/" + fileName
+                    : fileName;
+            return fileClient.renameWithResponse(null, destinationPath, null, 
destinationCondition, null, null).getValue();
+        } catch (DataLakeStorageException dataLakeStorageException) {
+            getLogger().error("Error while renaming temp file on Azure Data 
Lake Storage", dataLakeStorageException);

Review comment:
       What behavior is expected for the temp file if rename is unsuccessful? 




-- 
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to