From 22924c656bfdcf749bd618f055ffa816aca17ae5 Mon Sep 17 00:00:00 2001 From: Joe Date: Sat, 17 Oct 2015 10:46:49 -0400 Subject: [PATCH] NIFI-995 TestGetFile.testAttributes() failed in case of a NTFS partition in Linux, because Files.setPosixFilePermissions() did not have any effect on the files and did not throw Exception. closes #95. Signed off by Tony Kurc (tkurc@apache.org) --- .../nifi/processors/standard/TestGetFile.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetFile.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetFile.java index 018cbdc330..eb8a764235 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetFile.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetFile.java @@ -26,6 +26,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.attribute.PosixFilePermission; import java.nio.file.attribute.PosixFilePermissions; import java.text.DateFormat; import java.text.ParseException; @@ -33,6 +34,7 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Locale; +import java.util.Set; import org.apache.nifi.flowfile.attributes.CoreAttributes; import org.apache.nifi.util.MockFlowFile; @@ -158,8 +160,23 @@ public class TestGetFile { boolean verifyPermissions = false; try { - Files.setPosixFilePermissions(targetPath, PosixFilePermissions.fromString("r--r-----")); - verifyPermissions = true; + // If you mount an NTFS partition in Linux, you are unable to change the permissions of the files, + // because every file has the same permissions, controlled by the 'fmask' and 'dmask' mount options. + // Executing a chmod command will not fail, but it does not change the file's permissions. + // From Java perspective the NTFS mount point, as a FileStore supports the 'unix' and 'posix' file + // attribute views, but the setPosixFilePermissions() has no effect. + // + // If you set verifyPermissions to true without the following extra check, the test case will fail + // on a file system, where Nifi source is located on a NTFS mount point in Linux. + // The purpose of the extra check is to ensure, that setPosixFilePermissions() changes the file's + // permissions, and set verifyPermissions, after we are convinced. + Set perms = PosixFilePermissions.fromString("r--r-----"); + Files.setPosixFilePermissions(targetPath, perms); + Set permsAfterSet = Files.getPosixFilePermissions(targetPath); + if (perms.equals(permsAfterSet)) { + verifyPermissions = true; + } + } catch (Exception donothing) { }