private File occupyFile(File own, ru.vassaev.core.thread.Process prc
, Context cntx, File from_dir, boolean subdirectories) throws SysException {
if (!from_dir.exists()) {
boolean b = from_dir.mkdirs();
if (!b)
throw new SysException("Impossible creating directory with path '" + from_dir.getAbsolutePath() + "'");
}
if (!from_dir.isDirectory())
throw new SysException(from_dir.getAbsolutePath() + " is a file");
File[] fls = from_dir.listFiles();
for (int i = 0; i < fls.length; i++) {
File fl = fls[i];
if (subdirectories && fl.isDirectory()) {
File x = occupyFile(own, prc, cntx, fl, subdirectories);
if (x == null)
continue;
else
return x;
}
if (fl.isFile()) {
cntx.log(false, "found file '", fl.getAbsolutePath(), "'");
String lm = Long.toString(fl.lastModified());
prc.regResourceName(fl.getName(), "file.NAME");
prc.regResourceName(lm, "file.LM");
prc.regResourceName(fl.getParent(), "file.PATH");
prc.regResourceName(fl.getAbsolutePath(), "file.FULLNAME");
File f = fl.getParentFile();
StringBuffer s = new StringBuffer();
while (!own.equals(f)) {
s.insert(0, f.getName()).insert(0, File.separatorChar);
f = f.getParentFile();
}
regResourceName(s, "file.RPATH");
String prc_dir = cntx.getPrmString("path_prc");
if (prc_dir == null || prc_dir.length() == 0) {
String skip_dir = cntx.getPrmString("path_skip");
if (skip_dir == null || skip_dir.length() == 0) {
fl.delete();
cntx.log(false, fl.getAbsolutePath(), " was deleted");
continue;
}
File skip_d = new File(skip_dir.toString());
if (!skip_d.exists()) {
boolean b = skip_d.mkdirs();
if (!b)
throw new SysException("Impossible creating directory with path '" + skip_d.getAbsolutePath() + "'");
}
StringBuffer skip_file = new StringBuffer().append(skip_dir)
.append(File.separatorChar).append(fl.getName()).append('.').append(System.nanoTime());
cntx.log(false, fl.getAbsolutePath(), " was skipped and removed to ", skip_file);
} else {
File prc_d = new File(prc_dir.toString());
if (!prc_d.exists()) {
boolean b = prc_d.mkdirs();
if (!b)
throw new SysException("Impossible creating directory with path '" + prc_d.getAbsolutePath() + "'");
}
StringBuffer prc_file = new StringBuffer().append(prc_dir)
.append(File.separatorChar).append(fl.getName()).append('.').append(System.nanoTime());
File prc_fl = new File(prc_file.toString());
if (fl.renameTo(prc_fl))