Mercurial > dive4elements > river
view flys-backend/src/main/java/de/intevation/flys/utils/FileTools.java @ 771:6dc847194625
Removed trailing whitespace.
flys-backend/trunk@2241 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 26 Jun 2011 17:13:53 +0000 |
parents | 31895d24387e |
children | c7370734b872 |
line wrap: on
line source
package de.intevation.flys.utils; import java.io.File; import java.util.Stack; import org.apache.log4j.Logger; public class FileTools { private static Logger log = Logger.getLogger(FileTools.class); private FileTools() { } public static File repair(File file) { file = file.getAbsoluteFile(); if (file.exists()) { return file; } Stack<String> parts = new Stack<String>(); File curr = file; while (curr != null) { String name = curr.getName(); if (name.length() > 0) { parts.push(curr.getName()); } curr = curr.getParentFile(); } curr = null; OUTER: while (!parts.isEmpty()) { String f = parts.pop(); log.debug("fixing: '" + f + "'"); if (curr == null) { // XXX: Not totaly correct because there // more than one root on none unix systems. for (File root: File.listRoots()) { File [] files = root.listFiles(); if (files == null) { log.warn("cannot list '" + root); continue; } for (File candidate: files) { if (candidate.getName().equalsIgnoreCase(f)) { curr = new File(root, candidate.getName()); continue OUTER; } } } break; } else { File [] files = curr.listFiles(); if (files == null) { log.warn("cannot list: '" + curr + "'"); return file; } for (File candidate: files) { if (candidate.getName().equalsIgnoreCase(f)) { curr = new File(curr, candidate.getName()); continue OUTER; } } curr = null; break; } } if (curr == null) { log.warn("cannot repair path '" + file + "'"); return file; } return curr; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :