Merge "idegen: Handle symbolic link that targets to current or parent directory" am: d6c9ae2806 am: e78fac030c

Original change: https://android-review.googlesource.com/c/platform/development/+/2203929

Change-Id: I0b80faa79788f972ead85973dc8482e5e81226ff
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot
2022-09-30 07:15:02 +00:00
committed by Automerger Merge Worker

View File

@@ -18,6 +18,8 @@ import java.io.File;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -153,6 +155,17 @@ public class Configuration {
continue;
}
if (Files.isSymbolicLink(file.toPath())) {
Path target = Files.readSymbolicLink(file.toPath()).normalize();
if (target.startsWith("") || target.startsWith(".")
|| target.startsWith("..")) {
// Don't recurse symbolic link that targets to parent
// or current directory.
Log.debug("Skipped: " + path);
continue;
}
}
if (file.isDirectory()) {
// Traverse nested directories.
if (excludes.exclude(path)) {
@@ -216,8 +229,7 @@ public class Configuration {
* found.
*/
private static String parsePackageName(File file) throws IOException {
BufferedReader in = new BufferedReader(new FileReader(file));
try {
try (BufferedReader in = new BufferedReader(new FileReader(file))) {
String line;
while ((line = in.readLine()) != null) {
String trimmed = line.trim();
@@ -230,8 +242,6 @@ public class Configuration {
}
return null;
} finally {
in.close();
}
}