01: /*
02: * This file is part of DrFTPD, Distributed FTP Daemon.
03: *
04: * DrFTPD is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * DrFTPD is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with DrFTPD; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18: package org.drftpd.remotefile;
19:
20: import java.io.FileNotFoundException;
21: import java.util.Iterator;
22:
23: import net.sf.drftpd.ObjectNotFoundException;
24:
25: /**
26: * @author mog
27: * @version $Id: FileUtils.java 1380 2005-12-26 21:04:37Z tdsoul $
28: */
29: public class FileUtils {
30: /**
31: * private constructor, not instantiable
32: */
33: private FileUtils() {
34: }
35:
36: public static LinkedRemoteFileInterface getSubdirOfDirectory(
37: LinkedRemoteFileInterface baseDir,
38: LinkedRemoteFileInterface dir) throws FileNotFoundException {
39: LinkedRemoteFileInterface dir2 = dir;
40:
41: while (dir != baseDir) {
42: dir2 = dir;
43: dir = dir.getParentFile();
44: }
45:
46: return dir2;
47: }
48:
49: public static LinkedRemoteFile getOldestFile(
50: LinkedRemoteFileInterface dir)
51: throws ObjectNotFoundException {
52: Iterator iter = dir.getFiles().iterator();
53: if (!iter.hasNext())
54: throw new ObjectNotFoundException();
55:
56: LinkedRemoteFile oldestFile = (LinkedRemoteFile) iter.next();
57:
58: for (; iter.hasNext();) {
59: LinkedRemoteFile file = (LinkedRemoteFile) iter.next();
60: if (file.isDirectory()) {
61: try {
62: LinkedRemoteFile oldestFile2 = getOldestFile(file);
63: if (oldestFile.lastModified() > oldestFile2
64: .lastModified())
65: oldestFile = oldestFile2;
66: } catch (ObjectNotFoundException e) {
67: continue;
68: }
69: } else if (oldestFile.lastModified() > file.lastModified()) {
70: oldestFile = file;
71: }
72: }
73:
74: return oldestFile;
75: }
76: }
|