Dateiverwaltung für die WebBox
ulrich
2017-03-05 fab629ffb99008bce86082033d349f42ba13b93a
redundanz bei copy und move beseitigt
1 files modified
40 ■■■■■ changed files
src/java/de/uhilger/filecms/api/FileMgr.java 40 ●●●●● patch | view | raw | blame | history
src/java/de/uhilger/filecms/api/FileMgr.java
@@ -166,32 +166,14 @@
  }
  
  public String copyFiles(String fromPath, String toPath, List fileNames) {
    String result = null;
    try {
      File srcDir = getTargetDir(fromPath);
      File targetDir = getTargetDir(toPath);
      Iterator i = fileNames.iterator();
      while(i.hasNext()) {
        Object o = i.next();
        if (o instanceof ArrayList) {
          ArrayList al = (ArrayList) o;
          File srcFile = new File(srcDir, al.get(0).toString());
          if(srcFile.isDirectory()) {
            logger.fine("copy dir " + srcFile.getAbsolutePath() + " to dir " + targetDir.getAbsolutePath());
            FileUtils.copyDirectoryToDirectory(srcFile, targetDir);
          } else {
            logger.fine("copy srcFile " + srcFile.getAbsolutePath() + " to dir " + targetDir.getAbsolutePath());
            FileUtils.copyFileToDirectory(srcFile, targetDir);
          }
        }
      }
    } catch (IOException ex) {
      logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
    }
    return result;
    return copyOrMoveFiles(fromPath, toPath, fileNames, OP_COPY);
  }
  
  public String moveFiles(String fromPath, String toPath, List fileNames) {
    return copyOrMoveFiles(fromPath, toPath, fileNames, OP_MOVE);
  }
  private String copyOrMoveFiles(String fromPath, String toPath, List fileNames, int operation) {
    String result = null;
    try {
      File srcDir = getTargetDir(fromPath);
@@ -203,9 +185,17 @@
          ArrayList al = (ArrayList) o;
          File srcFile = new File(srcDir, al.get(0).toString());
          if(srcFile.isDirectory()) {
            FileUtils.moveDirectoryToDirectory(srcFile, targetDir, false);
            if(operation == OP_MOVE) {
              FileUtils.moveDirectoryToDirectory(srcFile, targetDir, false);
            } else {
              FileUtils.copyDirectoryToDirectory(srcFile, targetDir);
            }
          } else {
            FileUtils.moveFileToDirectory(srcFile, targetDir, false);
            if(operation == OP_MOVE) {
              FileUtils.moveFileToDirectory(srcFile, targetDir, false);
            } else {
              FileUtils.copyFileToDirectory(srcFile, targetDir);
            }
          }
        }
      }