test/java/io/pathNames/General.java
Print this page
@@ -38,11 +38,11 @@
private static int gensymCounter = 0;
/* Generate a filename unique to this run */
- private static String gensym() {
+ protected static String gensym() {
return "x." + ++gensymCounter;
}
/**
@@ -125,13 +125,13 @@
if (dl == null) {
throw new RuntimeException("Can't list " + dir);
}
for (int i = 0; i < dl.length; i++) {
File f = new File(d, dl[i]);
- if (f.isDirectory() && f.canRead()) {
+ if (f.isDirectory()) {
String[] dl2 = f.list();
- if (dl2.length >= 250) {
+ if (dl2 == null || dl2.length >= 250) {
/* Heuristic to avoid scanning huge directories */
continue;
}
return dl[i];
}
@@ -275,12 +275,12 @@
String ans, String ask, String slash)
throws Exception
{
check(ans, ask + slash);
checkNames(depth, create,
- ans.endsWith(File.separator) ? ans : ans + File.separator,
- ask + slash);
+ ans,
+ ask);
}
/** Check slash cases for the given ask string */
public static void checkSlashes(int depth, boolean create,
@@ -306,17 +306,20 @@
/** Check name cases for the given ask string */
public static void checkNames(int depth, boolean create,
String ans, String ask)
throws Exception
{
+ ans = ans.endsWith(File.separator) ? ans : ans + File.separator;
+ ask = ask.endsWith(File.separator) ? ask : ask + File.separator;
+
int d = depth - 1;
File f = new File(ans);
String n;
/* Normal name */
if (f.exists()) {
- if (f.isDirectory() && f.canRead()) {
+ if (f.isDirectory() && f.list() != null) {
if ((n = findSomeFile(ans, create)) != null)
checkSlashes(d, create, ans + n, ask + n);
if ((n = findSomeDir(ans, create)) != null)
checkSlashes(d, create, ans + n, ask + n);
}