|
16 | 16 | import java.lang.foreign.FunctionDescriptor;
|
17 | 17 | import java.lang.foreign.MemorySegment;
|
18 | 18 | import java.lang.invoke.MethodHandle;
|
| 19 | +import java.nio.file.FileVisitResult; |
19 | 20 | import java.nio.file.Files;
|
20 | 21 | import java.nio.file.Path;
|
21 | 22 | import java.nio.file.Paths;
|
| 23 | +import java.nio.file.SimpleFileVisitor; |
| 24 | +import java.nio.file.attribute.BasicFileAttributes; |
| 25 | +import java.util.ArrayList; |
22 | 26 | import java.util.Arrays;
|
23 | 27 | import java.util.List;
|
24 | 28 |
|
@@ -61,17 +65,36 @@ static List<String> findLibSystemd() {
|
61 | 65 | // so we must manually check the library path to find what we need.
|
62 | 66 | final Path libsystemd = Paths.get("libsystemd.so.0");
|
63 | 67 | final String libpath = System.getProperty("java.library.path");
|
64 |
| - return Arrays.stream(libpath.split(":")).map(Paths::get).filter(Files::exists).flatMap(p -> { |
| 68 | + final List<String> foundPaths = new ArrayList<>(); |
| 69 | + Arrays.stream(libpath.split(":")).map(Paths::get).filter(Files::exists).forEach(rootPath -> { |
65 | 70 | try {
|
66 |
| - return Files.find( |
67 |
| - p, |
68 |
| - Integer.MAX_VALUE, |
69 |
| - (fp, attrs) -> (attrs.isDirectory() == false && fp.getFileName().equals(libsystemd)) |
70 |
| - ); |
| 71 | + Files.walkFileTree(rootPath, new SimpleFileVisitor<>() { |
| 72 | + @Override |
| 73 | + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { |
| 74 | + if (Files.isReadable(dir)) { |
| 75 | + return FileVisitResult.CONTINUE; |
| 76 | + } |
| 77 | + return FileVisitResult.SKIP_SUBTREE; |
| 78 | + } |
| 79 | + |
| 80 | + @Override |
| 81 | + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { |
| 82 | + if (file.getFileName().equals(libsystemd)) { |
| 83 | + foundPaths.add(file.toAbsolutePath().toString()); |
| 84 | + } |
| 85 | + return FileVisitResult.CONTINUE; |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + public FileVisitResult visitFileFailed(Path file, IOException exc) { |
| 90 | + return FileVisitResult.CONTINUE; |
| 91 | + } |
| 92 | + }); |
71 | 93 | } catch (IOException e) {
|
72 | 94 | throw new UncheckedIOException(e);
|
73 | 95 | }
|
74 |
| - }).map(p -> p.toAbsolutePath().toString()).toList(); |
| 96 | + }); |
| 97 | + return foundPaths; |
75 | 98 | }
|
76 | 99 |
|
77 | 100 | private static final MethodHandle sd_notify$mh = downcallHandle("sd_notify", FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS));
|
|
0 commit comments