Skip to content

Commit

Permalink
'#1861 Also the java.io.File API gives wrong answer, false, when testing
Browse files Browse the repository at this point in the history
if an instance is an directory if the name of dir contains a trailing
space. A workaround was possible and implemented.
  • Loading branch information
patrickdalla committed Sep 25, 2023
1 parent 11123b3 commit 9f61164
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion iped-utils/src/main/java/iped/utils/FileInputStreamFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.NotDirectoryException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
Expand All @@ -32,7 +33,7 @@ public Path getPath(String subPath) {
}
if (IS_WINDOWS) {
// workaround for https://github.com/sepinf-inc/IPED/issues/1861
if (file.isDirectory()) {
if (isDirectory(file.getAbsolutePath())) {
try {
file = Files.createTempDirectory("iped").toFile();
file.deleteOnExit();
Expand All @@ -54,6 +55,17 @@ public Path getPath(String subPath) {
}
}

boolean isDirectory(String path) {
try {
Files.newDirectoryStream(Path.of(path));
} catch (NotDirectoryException ioe) {
return false;
} catch (Exception e) {
return true;
}
return true;
}

@Override
public SeekableInputStream getSeekableInputStream(String subPath) throws IOException {
File file = getPath(subPath).toFile();
Expand Down

0 comments on commit 9f61164

Please sign in to comment.