private static void purgeFiles() {
    File purge = new File("purge");
    String action = configuration.getPluginPurgeAction();

    if (action.equalsIgnoreCase("none")) {
      purge.delete();
      return;
    }

    try {
      try (FileInputStream fis = new FileInputStream(purge);
          BufferedReader in = new BufferedReader(new InputStreamReader(fis))) {
        String line;

        while ((line = in.readLine()) != null) {
          File f = new File(line);

          if (action.equalsIgnoreCase("delete")) {
            f.delete();
          } else if (action.equalsIgnoreCase("backup")) {
            FileUtils.moveFileToDirectory(f, new File("backup"), true);
            f.delete();
          }
        }
      }
    } catch (IOException e) {
    }
    purge.delete();
  }
Exemplo n.º 2
0
 public static void moveFileToDirectory(File srcFile, File destDir, boolean createDestDir) {
   try {
     FileUtils.moveFileToDirectory(srcFile, destDir, createDestDir);
   } catch (IOException e) {
     throw new UncheckedIOException(e);
   }
 }
Exemplo n.º 3
0
 public void moveToDirectory(File target) {
   if (target.exists() && !target.isDirectory()) {
     throw new RuntimeException(String.format("Target '%s' is not a directory", target));
   }
   try {
     FileUtils.moveFileToDirectory(this, target, true);
   } catch (IOException e) {
     throw new RuntimeException(
         String.format("Could not move test file '%s' to directory '%s'", this, target), e);
   }
 }
Exemplo n.º 4
0
  private void archiveFile(File file) {
    try {
      LOGGER.info("Archiving file " + file.getAbsolutePath());

      new File(archiveDirectoryPath + "/" + file.getName()).delete();

      FileUtils.moveFileToDirectory(file, archiveDirectory, true);
    } catch (IOException ioEx) {
      LOGGER.error("Error while arhiving file " + file.getAbsolutePath() + ".", ioEx);
    }
  }
Exemplo n.º 5
0
 /**
  * Check server paths; warn if existing deprecated paths. Override this method to perform server
  * specific checks.
  *
  * @throws ConfigurationException If deprecated paths have been detected
  * @since 5.4.2
  */
 public void checkPaths() throws ConfigurationException {
   File badInstanceClid =
       new File(generator.getNuxeoHome(), getDefaultDataDir() + File.separator + "instance.clid");
   if (badInstanceClid.exists()
       && !getDataDir().equals(new File(generator.getNuxeoHome(), getDefaultDataDir()))) {
     log.warn("Moving " + badInstanceClid + " to " + getDataDir() + ".");
     try {
       FileUtils.moveFileToDirectory(badInstanceClid, getDataDir(), true);
     } catch (IOException e) {
       throw new ConfigurationException("Move failed.", e);
     }
   }
 }
Exemplo n.º 6
0
 /** Перенос скаченной и разархивированной БД на место старой базы */
 private void moveDB() {
   try {
     File oldDB = new File(PATH_TO_DB.replace(";TRACE_LEVEL_FILE=0", "") + ".h2.db");
     File newDB = new File(getClass().getResource(RES_PATH + DB_NAME).toURI());
     if ((oldDB.exists() && oldDB.isFile()) && (newDB.exists() && newDB.isFile())) {
       FileUtils.deleteQuietly(oldDB);
       String DBPath = PATH_TO_DB.replace("GoodwillCatalog;TRACE_LEVEL_FILE=0", "");
       File DBDir = new File(DBPath);
       FileUtils.moveFileToDirectory(newDB, DBDir, false);
       System.out.println("DB integrated!");
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 7
0
  @Override
  public String process() throws Exception {
    File file = getContext().getFileToProcess(FolderType.valueOf(from));
    File destinationFolder = getContext().getFolder(FolderType.valueOf(to));

    try {
      getLogger(this.getClass().getName())
          .log(Level.INFO, "Moving file " + file + " to " + destinationFolder);
      moveFileToDirectory(file, destinationFolder, false);
    } catch (FileExistsException e) {
      getLogger(this.getClass().getName())
          .log(Level.WARNING, "File " + file + " already exists at " + destinationFolder);
    }

    return "COMPLETED";
  }
  @RequestMapping("move")
  public String move(
      @RequestParam(value = "descPath") String descPath,
      @RequestParam(value = "paths") String[] paths,
      @RequestParam(value = "conflict") String conflict,
      RedirectAttributes redirectAttributes)
      throws IOException {

    String rootPath = sc.getRealPath(ROOT_DIR);
    descPath = URLDecoder.decode(descPath, Constants.ENCODING);

    for (int i = 0, l = paths.length; i < l; i++) {
      String path = paths[i];
      path = URLDecoder.decode(path, Constants.ENCODING);
      paths[i] = (rootPath + File.separator + path).replace("\\", "/");
    }

    try {
      File descPathFile = new File(rootPath + File.separator + descPath);
      for (String path : paths) {
        File sourceFile = new File(path);
        File descFile = new File(descPathFile, sourceFile.getName());
        if (descFile.exists() && "ignore".equals(conflict)) {
          continue;
        }

        FileUtils.deleteQuietly(descFile);

        if (sourceFile.isDirectory()) {
          FileUtils.moveDirectoryToDirectory(sourceFile, descPathFile, true);
        } else {
          FileUtils.moveFileToDirectory(sourceFile, descPathFile, true);
        }
      }
      redirectAttributes.addFlashAttribute(Constants.MESSAGE, "移动成功!");
    } catch (Exception e) {
      redirectAttributes.addFlashAttribute(Constants.ERROR, e.getMessage());
    }

    redirectAttributes.addAttribute("path", URLEncoder.encode(descPath, Constants.ENCODING));
    return redirectToUrl(viewName("list"));
  }
Exemplo n.º 9
0
  private void moveLegacyTimeline() throws IOException {
    File timelineDir = applicationConfiguration.getWorkingDirectory(TIMELINE_BASEDIR);

    File legacyIndexDir = timelineDir;

    File newIndexDir = new File(timelineDir, "index");

    File[] legacyIndexFiles =
        legacyIndexDir.listFiles(
            new FileFilter() {
              public boolean accept(File file) {
                return file.isFile();
              }
            });

    if (legacyIndexFiles == null || legacyIndexFiles.length == 0) {
      return;
    }

    if (newIndexDir.exists() && newIndexDir.listFiles().length > 0) {
      return;
    }

    getLogger()
        .info(
            "Moving legacy timeline index from '"
                + legacyIndexDir.getAbsolutePath()
                + "' to '"
                + newIndexDir.getAbsolutePath()
                + "'.");

    if (!newIndexDir.exists()) {
      newIndexDir.mkdirs();
    }

    for (File legacyIndexFile : legacyIndexFiles) {
      FileUtils.moveFileToDirectory(legacyIndexFile, newIndexDir, false);
    }
  }
Exemplo n.º 10
0
 public static void moveFile(File srcFile, File destDir, boolean createDestDir)
     throws IOException {
   FileUtils.moveFileToDirectory(srcFile, destDir, createDestDir);
 }