Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/org/codehaus/plexus/util/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,9 @@
IOException exception = null;

final File[] files = directory.listFiles();
if (files == null) {
throw new IOException("Could not list directory " + directory.getAbsolutePath());
}
for (final File file : files) {
try {
forceDeleteOnExit(file);
Expand Down Expand Up @@ -1762,6 +1765,9 @@
}

File[] files = sourceDirectory.listFiles();
if (files == null) {
throw new IOException("Could not list directory " + sourceDirectory.getAbsolutePath());
}

String sourcePath = sourceDirectory.getAbsolutePath();

Expand Down Expand Up @@ -1922,9 +1928,9 @@
fileReader = null;
} finally {
//noinspection deprecation
IOUtil.close(fileReader);

Check warning on line 1931 in src/main/java/org/codehaus/plexus/util/FileUtils.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-26.04 jdk-25-zulu 3.10.0

close(java.io.Reader) in org.codehaus.plexus.util.IOUtil has been deprecated

Check warning on line 1931 in src/main/java/org/codehaus/plexus/util/FileUtils.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / macos-latest jdk-25-zulu 3.10.0

close(java.io.Reader) in org.codehaus.plexus.util.IOUtil has been deprecated

Check warning on line 1931 in src/main/java/org/codehaus/plexus/util/FileUtils.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-latest jdk-25-zulu 3.10.0

close(java.io.Reader) in org.codehaus.plexus.util.IOUtil has been deprecated

Check warning on line 1931 in src/main/java/org/codehaus/plexus/util/FileUtils.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-latest jdk-8-zulu 3.10.0

close(java.io.Reader) in org.codehaus.plexus.util.IOUtil has been deprecated

Check warning on line 1931 in src/main/java/org/codehaus/plexus/util/FileUtils.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-latest jdk-21-zulu 3.10.0

close(java.io.Reader) in org.codehaus.plexus.util.IOUtil has been deprecated
//noinspection deprecation
IOUtil.close(fileWriter);

Check warning on line 1933 in src/main/java/org/codehaus/plexus/util/FileUtils.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-26.04 jdk-25-zulu 3.10.0

close(java.io.Writer) in org.codehaus.plexus.util.IOUtil has been deprecated

Check warning on line 1933 in src/main/java/org/codehaus/plexus/util/FileUtils.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / macos-latest jdk-25-zulu 3.10.0

close(java.io.Writer) in org.codehaus.plexus.util.IOUtil has been deprecated

Check warning on line 1933 in src/main/java/org/codehaus/plexus/util/FileUtils.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-latest jdk-25-zulu 3.10.0

close(java.io.Writer) in org.codehaus.plexus.util.IOUtil has been deprecated

Check warning on line 1933 in src/main/java/org/codehaus/plexus/util/FileUtils.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-latest jdk-8-zulu 3.10.0

close(java.io.Writer) in org.codehaus.plexus.util.IOUtil has been deprecated

Check warning on line 1933 in src/main/java/org/codehaus/plexus/util/FileUtils.java

View workflow job for this annotation

GitHub Actions / Build it / Verify / ubuntu-latest jdk-21-zulu 3.10.0

close(java.io.Writer) in org.codehaus.plexus.util.IOUtil has been deprecated
}
} else {
if (isSourceNewerThanDestination(from, to) || overwrite) {
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/org/codehaus/plexus/util/FileUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.junit.jupiter.api.condition.OS;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

/**
* This is used to test FileUtils for correctness.
Expand Down Expand Up @@ -679,6 +680,21 @@ void removeExtensionWithPaths() {
}
}

@Test
void copyDirectoryStructureFailsWhenSourceCannotBeListed() throws Exception {
File from = new File(getTestDirectory(), "unlistable");
from.mkdirs();
File to = new File(getTestDirectory(), "unlistable-copy");
assumeTrue(from.setReadable(false) && from.setExecutable(false) && from.listFiles() == null);
try {
IOException e = assertThrows(IOException.class, () -> FileUtils.copyDirectoryStructure(from, to));
assertTrue(e.getMessage().contains(from.getAbsolutePath()));
} finally {
from.setExecutable(true);
from.setReadable(true);
}
}

@Test
void copyDirectoryStructureWithAEmptyDirectoryStructure() throws Exception {
File from = new File(getTestDirectory(), "from");
Expand Down
Loading