Esempio n. 1
0
  /** {@inheritDoc} */
  @Override
  protected URL createStorage() throws FileNotFoundException, IOException {
    FileNameProducer fnp =
        new FileNameProducer(
            config.getRepository(),
            config.getWorkspace(),
            PrivilegedFileHelper.getAbsolutePath(config.getBackupDir()),
            super.timeStamp,
            true,
            true);

    return new URL("file:" + PrivilegedFileHelper.getAbsolutePath(fnp.getNextFile()));
  }
Esempio n. 2
0
  /**
   * Remove all file of workspace index.
   *
   * @param wsConfig - workspace configuration.
   * @param isSystem - 'true' to clean system workspace.
   * @throws RepositoryConfigurationException - exception on parsing workspace configuration
   * @throws IOException - exception on remove index folder
   */
  public void removeWorkspaceIndex(WorkspaceEntry wsConfig, boolean isSystem)
      throws RepositoryConfigurationException, IOException {
    String indexDirName =
        wsConfig.getQueryHandler().getParameterValue(QueryHandlerParams.PARAM_INDEX_DIR);

    File indexDir = new File(indexDirName);
    if (PrivilegedFileHelper.exists(indexDir)) {
      removeFolder(indexDir);
    }

    if (isSystem) {
      File systemIndexDir = new File(indexDirName + "_" + SystemSearchManager.INDEX_DIR_SUFFIX);
      if (PrivilegedFileHelper.exists(systemIndexDir)) {
        removeFolder(systemIndexDir);
      }
    }
  }
Esempio n. 3
0
  protected void prepareCache() {
    String cacheFolderName = configuration.getCacheFolderName();

    File cacheFolder = new File(cacheFolderName);

    if (!PrivilegedFileHelper.exists(cacheFolder)) {
      LOG.info("Cache folder not exist. Try to create it...");
      PrivilegedFileHelper.mkdirs(cacheFolder);
    }

    String[] cacheFiles = PrivilegedFileHelper.list(cacheFolder);
    if (cacheFiles == null) {
      LOG.info("No cache file in cache folder!");
      return;
    }

    for (String cacheFile : cacheFiles) {
      if (cacheFile.endsWith(FtpConst.FTP_CACHEFILEEXTENTION)) {
        File file = new File(cacheFolderName + "/" + cacheFile);
        PrivilegedFileHelper.delete(file);
      }
    }
  }
Esempio n. 4
0
  /** Remove folder */
  private void removeFolder(File dir) throws IOException {
    if (PrivilegedFileHelper.isDirectory(dir)) {
      for (File subFile : PrivilegedFileHelper.listFiles(dir)) {
        removeFolder(subFile);
      }

      if (!PrivilegedFileHelper.delete(dir)) {
        throw new IOException(
            "Index folder was not deleted : " + PrivilegedFileHelper.getCanonicalPath(dir));
      }
    } else {
      if (!PrivilegedFileHelper.delete(dir)) {
        throw new IOException(
            "Index file was not deleted : " + PrivilegedFileHelper.getCanonicalPath(dir));
      }
    }
  }