You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2020/07/29 07:48:14 UTC
[GitHub] [commons-io] cosmoJFH opened a new pull request #131: new test copyFileWrongPermissions
cosmoJFH opened a new pull request #131:
URL: https://github.com/apache/commons-io/pull/131
New test to reflect issue https://issues.apache.org/jira/browse/IO-678.
Note that the issue is related to the permission in temporary folders.
I have copied the junit 4 method TemporaryFolder.createTemporaryFolderIn, since in my project we do not make use of junit 5.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [commons-io] garydgregory commented on a change in pull request #131: new test copyFileWrongPermissions
Posted by GitBox <gi...@apache.org>.
garydgregory commented on a change in pull request #131:
URL: https://github.com/apache/commons-io/pull/131#discussion_r462625381
##########
File path: src/test/java/org/apache/commons/io/FileUtilsCopyDirectoryToDirectoryTestCase.java
##########
@@ -73,6 +83,48 @@ public void copyDirectoryToDirectoryThrowsNullPointerExceptionWithCorrectMessage
assertExceptionTypeAndMessage(srcDir, destDir, NullPointerException.class, "destinationDir");
}
+
+ @Test
+ public void copyFileWrongPermissions() throws IOException {
+
+
+ final File destDir = createTemporaryFolderIn(null);
+ final Path srcFile = Files.createTempFile("tmp-output", ".xml");
+ final Path path = Paths.get(destDir.getAbsolutePath(), "newFile.xml");
+
+ try {
+ FileUtils.copyFile(srcFile.toFile(), path.toFile());
+ } catch (IllegalArgumentException iae) {
+ iae.printStackTrace();
+ }
+
+ assertTrue(Files.getPosixFilePermissions(path).contains(PosixFilePermission.OTHERS_READ), Files.getPosixFilePermissions(path).toString());
Review comment:
@cosmoJFH
Here you are testing that a target path has a certain attribute but you are not checking that this attribute was in fact present in the source.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [commons-io] garydgregory commented on a change in pull request #131: new test copyFileWrongPermissions
Posted by GitBox <gi...@apache.org>.
garydgregory commented on a change in pull request #131:
URL: https://github.com/apache/commons-io/pull/131#discussion_r461675952
##########
File path: src/test/java/org/apache/commons/io/FileUtilsCopyDirectoryToDirectoryTestCase.java
##########
@@ -73,6 +83,48 @@ public void copyDirectoryToDirectoryThrowsNullPointerExceptionWithCorrectMessage
assertExceptionTypeAndMessage(srcDir, destDir, NullPointerException.class, "destinationDir");
}
+
+ @Test
+ public void copyFileWrongPermissions() throws IOException {
+
+
+ final File destDir = createTemporaryFolderIn(null);
+ final Path srcFile = Files.createTempFile("tmp-output", ".xml");
+ final Path path = Paths.get(destDir.getAbsolutePath(), "newFile.xml");
+
+ try {
+ FileUtils.copyFile(srcFile.toFile(), path.toFile());
+ } catch (IllegalArgumentException iae) {
+ iae.printStackTrace();
Review comment:
Don't catch and log to sys err. Just let the exception percolate up.
##########
File path: src/test/java/org/apache/commons/io/FileUtilsCopyDirectoryToDirectoryTestCase.java
##########
@@ -35,6 +40,11 @@
@TempDir
public File temporaryFolder;
+
Review comment:
Delete extra blank line.
##########
File path: src/test/java/org/apache/commons/io/FileUtilsCopyDirectoryToDirectoryTestCase.java
##########
@@ -73,6 +83,48 @@ public void copyDirectoryToDirectoryThrowsNullPointerExceptionWithCorrectMessage
assertExceptionTypeAndMessage(srcDir, destDir, NullPointerException.class, "destinationDir");
}
+
+ @Test
+ public void copyFileWrongPermissions() throws IOException {
+
+
+ final File destDir = createTemporaryFolderIn(null);
+ final Path srcFile = Files.createTempFile("tmp-output", ".xml");
+ final Path path = Paths.get(destDir.getAbsolutePath(), "newFile.xml");
+
+ try {
+ FileUtils.copyFile(srcFile.toFile(), path.toFile());
+ } catch (IllegalArgumentException iae) {
+ iae.printStackTrace();
+ }
+
+ assertTrue(Files.getPosixFilePermissions(path).contains(PosixFilePermission.OTHERS_READ), Files.getPosixFilePermissions(path).toString());
+
+ }
+
+
+
+ private File createTemporaryFolderIn(File parentFolder) throws IOException {
Review comment:
What is this all about? Since we are testing `FileUtils.copyFile()`, why do we need an extra level of temp folder beyond what the existing `temporaryFolder` provide?
##########
File path: src/test/java/org/apache/commons/io/FileUtilsCopyDirectoryToDirectoryTestCase.java
##########
@@ -73,6 +83,48 @@ public void copyDirectoryToDirectoryThrowsNullPointerExceptionWithCorrectMessage
assertExceptionTypeAndMessage(srcDir, destDir, NullPointerException.class, "destinationDir");
}
+
+ @Test
+ public void copyFileWrongPermissions() throws IOException {
+
Review comment:
Delete extra blank lines.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [commons-io] garydgregory commented on pull request #131: new test copyFileWrongPermissions
Posted by GitBox <gi...@apache.org>.
garydgregory commented on pull request #131:
URL: https://github.com/apache/commons-io/pull/131#issuecomment-1082381719
@cosmoJFH
Would you please review git master and see if this is still relevant, and if so, rebase?
--
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: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [commons-io] garydgregory commented on pull request #131: new test copyFileWrongPermissions
Posted by GitBox <gi...@apache.org>.
garydgregory commented on pull request #131:
URL: https://github.com/apache/commons-io/pull/131#issuecomment-665968579
@cosmoJFH
If you update this PR, may you please rebase on master?
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [commons-io] cosmoJFH commented on pull request #131: new test copyFileWrongPermissions
Posted by GitBox <gi...@apache.org>.
cosmoJFH commented on pull request #131:
URL: https://github.com/apache/commons-io/pull/131#issuecomment-666168635
I just wanted to spot a change in the code FileUtils.copyFile introduced in version 2.7.
In the example, a temporary file is made
final Path srcFile = Files.createTempFile("tmp-output", ".xml");
and then is copied by the method FileUtils.copyFile:
FileUtils.copyFile(srcFile.toFile(), path.toFile());
We checked the permissions of the copied file:
[OWNER_READ, OWNER_WRITE]
If the same code is executed by version 2.6, the permissions for the copied file are different
[OTHERS_READ, OWNER_READ, OWNER_WRITE, GROUP_READ, GROUP_WRITE]
The umask of our system is
$ umask -S
u=rwx,g=rwx,o=rx
It looks like in version 2.6 the umask is used while in version 2.7 the permissions of the source file are kept.
We don't really know which version of the code is the correct one.
----------------------------------------------------------------
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:
users@infra.apache.org