Skip to content

Commit f0bd378

Browse files
committed
Bugfix for listFiles for directories where the current user has no rights.
Reestablish JDK 1.3 compatibility for touch(). git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@140589 13f79535-47bb-0310-9956-ffa450edef68
1 parent b31de97 commit f0bd378

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

src/java/org/apache/commons/io/FileUtils.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
* @author <a href="mailto:jefft@apache.org">Jeff Turner</a>
6565
* @author Matthew Hawthorne
6666
* @author <a href="mailto:jeremias@apache.org">Jeremias Maerki</a>
67-
* @version $Id: FileUtils.java,v 1.34 2004/07/15 08:21:14 scolebourne Exp $
67+
* @version $Id: FileUtils.java,v 1.35 2004/07/15 09:16:17 jeremias Exp $
6868
*/
6969
public class FileUtils {
7070

@@ -121,19 +121,23 @@ public static String byteCountToDisplaySize(long size) {
121121
* @throws IOException If an I/O problem occurs
122122
*/
123123
public static void touch(File file) throws IOException {
124-
OutputStream out = new FileOutputStream(file, true);
125-
IOUtils.closeQuietly(out);
124+
if (!file.exists()) {
125+
OutputStream out = new FileOutputStream(file);
126+
IOUtils.closeQuietly(out);
127+
}
126128
file.setLastModified(System.currentTimeMillis());
127129
}
128130

129131

130132
private static void innerListFiles(Collection files, File directory, IOFileFilter filter) {
131133
File[] found = directory.listFiles((FileFilter)filter);
132-
for (int i = 0; i < found.length; i++) {
133-
if (found[i].isDirectory()) {
134-
innerListFiles(files, found[i], filter);
135-
} else {
136-
files.add(found[i]);
134+
if (found != null) {
135+
for (int i = 0; i < found.length; i++) {
136+
if (found[i].isDirectory()) {
137+
innerListFiles(files, found[i], filter);
138+
} else {
139+
files.add(found[i]);
140+
}
137141
}
138142
}
139143
}

0 commit comments

Comments
 (0)