110 return nf.getName(); 111 } 112 return null; 113 } 114 115 116 /** 117 * Construct a string that names a subdirectory of the given directory. 118 * If create is true, then create a subdirectory if none is found, and 119 * throw an exception if that is not possible; otherwise, return null if 120 * no subdirectory can be found. 121 */ 122 private static String findSomeDir(String dir, boolean create) { 123 File d = new File(dir); 124 String[] dl = d.list(); 125 if (dl == null) { 126 throw new RuntimeException("Can't list " + dir); 127 } 128 for (int i = 0; i < dl.length; i++) { 129 File f = new File(d, dl[i]); 130 if (f.isDirectory() && f.canRead()) { 131 String[] dl2 = f.list(); 132 if (dl2.length >= 250) { 133 /* Heuristic to avoid scanning huge directories */ 134 continue; 135 } 136 return dl[i]; 137 } 138 } 139 if (create) { 140 File sd = new File(d, gensym()); 141 if (sd.mkdir()) return sd.getName(); 142 } 143 return null; 144 } 145 146 147 /** Construct a string that does not name a file in the given directory */ 148 private static String findNon(String dir) { 149 File d = new File(dir); 150 String[] x = new String[] { "foo", "bar", "baz" }; 151 for (int i = 0; i < x.length; i++) { 152 File f = new File(d, x[i]); | 110 return nf.getName(); 111 } 112 return null; 113 } 114 115 116 /** 117 * Construct a string that names a subdirectory of the given directory. 118 * If create is true, then create a subdirectory if none is found, and 119 * throw an exception if that is not possible; otherwise, return null if 120 * no subdirectory can be found. 121 */ 122 private static String findSomeDir(String dir, boolean create) { 123 File d = new File(dir); 124 String[] dl = d.list(); 125 if (dl == null) { 126 throw new RuntimeException("Can't list " + dir); 127 } 128 for (int i = 0; i < dl.length; i++) { 129 File f = new File(d, dl[i]); 130 if (f.isDirectory()) { 131 String[] dl2 = f.list(); 132 if (dl2 == null || dl2.length >= 250) { 133 /* Heuristic to avoid scanning huge directories */ 134 continue; 135 } 136 return dl[i]; 137 } 138 } 139 if (create) { 140 File sd = new File(d, gensym()); 141 if (sd.mkdir()) return sd.getName(); 142 } 143 return null; 144 } 145 146 147 /** Construct a string that does not name a file in the given directory */ 148 private static String findNon(String dir) { 149 File d = new File(dir); 150 String[] x = new String[] { "foo", "bar", "baz" }; 151 for (int i = 0; i < x.length; i++) { 152 File f = new File(d, x[i]); |