Skip to content

Commit aad49eb

Browse files
author
Gary Gregory
committed
Move test method as new PathUtils.getAclEntryList(Path).
1 parent 857f0f3 commit aad49eb

3 files changed

Lines changed: 21 additions & 17 deletions

File tree

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ The <action> type attribute can be add,update,fix,remove.
8686
<action issue="IO-679" dev="ggregory" type="fix" due-to="proneel">
8787
input.AbstractCharacterFilterReader passes count of chars read #132.
8888
</action>
89+
<action dev="ggregory" type="add" due-to="Gary Gregory">
90+
Add PathUtils.getAclEntryList(Path).
91+
</action>
8992
<action dev="ggregory" type="fix" due-to="Gary Gregory">
9093
Replace FindBugs with SpotBugs.
9194
</action>

src/main/java/org/apache/commons/io/file/PathUtils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import java.nio.file.OpenOption;
3232
import java.nio.file.Path;
3333
import java.nio.file.Paths;
34+
import java.nio.file.attribute.AclEntry;
35+
import java.nio.file.attribute.AclFileAttributeView;
3436
import java.util.Arrays;
3537
import java.util.Collection;
3638
import java.util.Collections;
@@ -479,6 +481,20 @@ public static boolean fileContentEquals(final Path path1, final Path path2, fina
479481
}
480482
}
481483

484+
/**
485+
* Reads the access control list from a file attribute view.
486+
*
487+
* @param sourcePath the path to the file.
488+
* @return a file attribute view of the specified type, or null ifthe attribute view type is not available.
489+
* @throws IOException if an I/O error occurs.
490+
* @since 2.8.0
491+
*/
492+
public static List<AclEntry> getAclEntryList(final Path sourcePath) throws IOException {
493+
final AclFileAttributeView fileAttributeView = Files.getFileAttributeView(sourcePath,
494+
AclFileAttributeView.class);
495+
return fileAttributeView == null ? null : fileAttributeView.getAcl();
496+
}
497+
482498
/**
483499
* Returns whether the given file or directory is empty.
484500
*

src/test/java/org/apache/commons/io/FileUtilsCopyDirectoryToDirectoryTestCase.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@
2525
import java.nio.file.Path;
2626
import java.nio.file.Paths;
2727
import java.nio.file.StandardCopyOption;
28-
import java.nio.file.attribute.AclEntry;
29-
import java.nio.file.attribute.AclFileAttributeView;
30-
import java.util.List;
3128

29+
import org.apache.commons.io.file.PathUtils;
3230
import org.junit.jupiter.api.Test;
3331
import org.junit.jupiter.api.io.TempDir;
3432

@@ -58,7 +56,7 @@ private static void assertExceptionTypeAndMessage(final File srcDir, final File
5856
public File temporaryFolder;
5957

6058
private void assertAcl(final Path sourcePath, final Path destPath) throws IOException {
61-
assertEquals(getAclEntryList(sourcePath), getAclEntryList(destPath));
59+
assertEquals(PathUtils.getAclEntryList(sourcePath), PathUtils.getAclEntryList(destPath));
6260
}
6361

6462
@Test
@@ -116,17 +114,4 @@ public void copyFileAndCheckAcl() throws IOException {
116114
StandardCopyOption.COPY_ATTRIBUTES);
117115
assertAcl(sourcePath, destPath);
118116
}
119-
120-
/**
121-
* Gets a a file attribute view.
122-
*
123-
* @param sourcePath the path to the file.
124-
* @return a file attribute view of the specified type, or null ifthe attribute view type is not available.
125-
* @throws IOException if an I/O error occurs.
126-
*/
127-
private List<AclEntry> getAclEntryList(final Path sourcePath) throws IOException {
128-
final AclFileAttributeView fileAttributeView = Files.getFileAttributeView(sourcePath,
129-
AclFileAttributeView.class);
130-
return fileAttributeView == null ? null : fileAttributeView.getAcl();
131-
}
132117
}

0 commit comments

Comments
 (0)