Example usage for org.apache.commons.io FileUtils forceDelete

List of usage examples for org.apache.commons.io FileUtils forceDelete

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils forceDelete.

Prototype

public static void forceDelete(File file) throws IOException 

Source Link

Document

Deletes a file.

Usage

From source file:edu.ucsb.eucalyptus.storage.fs.FileSystemStorageManager.java

public void renameObjectRollback(String[] backup, String bucket, String oldName, String newName)
        throws IOException {
    if (backup == null || backup[0] == null || bucket == null || oldName == null || newName == null)
        return;//w  ww .  jav  a  2 s .co m

    File oldObjectFile = new File(rootDirectory + FILE_SEPARATOR + bucket + FILE_SEPARATOR + oldName);
    File newObjectFile = new File(rootDirectory + FILE_SEPARATOR + bucket + FILE_SEPARATOR + newName);
    File backupFile = new File(backup[0]);

    if (backupFile.exists()) {
        if (oldObjectFile.exists()) {
            FileUtils.forceDelete(backupFile);
        }
        if (newObjectFile.exists()) {
            FileUtils.moveFile(newObjectFile, oldObjectFile);
        }
        FileUtils.moveFile(backupFile, newObjectFile);
    }
}

From source file:com.taobao.android.builder.tools.cache.SimpleLocalCache.java

@Override
public void cacheFile(String type, String key, File file) throws FileCacheException {
    if (StringUtils.isEmpty(key)) {
        throw new FileCacheException("cache key is empty ");
    }//ww w. ja va2 s .  c  o  m
    File cacheFile = getLocalCacheFile(type, key);
    if (cacheFile.exists()) {
        throw new FileCacheException("file cache alerady exist:" + cacheFile.getAbsolutePath());
    }

    try {

        cacheFile.getParentFile().mkdirs();

        if (file.isFile()) {
            FileUtils.copyFile(file, cacheFile);
        } else {

            cacheFile.mkdirs();

            FileLockUtils.lock(cacheFile, new Runnable() {
                @Override
                public void run() {
                    try {
                        FileUtils.copyDirectory(file, cacheFile);
                    } catch (Throwable e) {
                        try {
                            FileUtils.forceDelete(cacheFile);
                        } catch (IOException e1) {
                            e1.printStackTrace();
                        }
                        throw new RuntimeException(e.getMessage(), e);
                    }
                }
            });
        }
    } catch (Throwable e) {
        throw new FileCacheException(e.getMessage(), e);
    }

}

From source file:com.meltmedia.cadmium.core.git.GitService.java

private static String initializeSnapshotDirectory(String warDir, Properties configProperties, String key,
        String checkoutDir, String snapshotDir) throws Exception, IOException {
    String renderedContentDir = configProperties.getProperty(key);
    log.debug("Making sure {} exists.", renderedContentDir);
    if (renderedContentDir == null || !FileSystemManager.exists(renderedContentDir)) {
        log.info(snapshotDir + " directory does not exist. Creating!!!");
        GitService rendered = null;/*from   w  ww  . j  av a  2 s  .  c o  m*/
        File snapshotFile = new File(warDir, snapshotDir);
        if (snapshotFile.exists()) {
            log.warn("{} exists @ {}, Deleting and recreating. ", snapshotDir, snapshotFile);
            FileUtils.forceDelete(snapshotFile);
        }
        try {
            rendered = GitService.cloneRepo(
                    new File(FileSystemManager.getChildDirectoryIfExists(warDir, checkoutDir), ".git")
                            .getAbsolutePath(),
                    snapshotFile.getAbsolutePath());
            renderedContentDir = rendered.getBaseDirectory();
            log.info("Removing .git directory from freshly cloned " + snapshotDir + " directory @ {}.",
                    renderedContentDir);
            String gitDir = FileSystemManager.getChildDirectoryIfExists(snapshotFile.getAbsolutePath(), ".git");
            if (gitDir != null) {
                FileSystemManager.deleteDeep(gitDir);
            }

        } finally {
            if (rendered != null) {
                rendered.close();
            }
        }
    }
    return renderedContentDir;
}

From source file:com.wavemaker.commons.util.IOUtils.java

public static void deleteDirectorySilently(File dir, boolean noLogging) {
    if (dir == null) {
        return;//  w  ww  .  j  av  a  2 s .  c o  m
    }
    try {
        FileUtils.forceDelete(dir);
    } catch (IOException e) {
        if (!noLogging) {
            logger.warn("Failed to delete the directory {}", dir, e);
        }
    }
}

From source file:net.nicholaswilliams.java.teamcity.plugin.buildNumber.PluginConfigurationServiceDefault.java

protected void copyXsdFileToDestination() {
    PluginConfigurationServiceDefault.logger.info("Copying distributed XSD file to TeamCity config directory.");

    try {//  w ww.j  a v a2s.c  om
        if (this.xsdFile.exists())
            FileUtils.forceDelete(this.xsdFile);

        PluginFileUtils.copyResource(this.getClass(), PluginConfigurationService.CONFIG_XSD_FILE_NAME,
                this.xsdFile);
    } catch (Exception e) {
        throw new FatalBeanException("Could not copy distributed configuration XSD file", e);
    }
}

From source file:com.taobao.android.builder.tasks.tpatch.TPatchDiffApkBuildTask.java

@TaskAction
public void doApkBuild() throws Exception {

    //TODO ?2zip//from w  w w .j av  a  2  s . c om
    apkFile = getApkFile();
    diffAPkFile = getDiffAPkFile();

    File tmpWorkDir = new File(diffAPkFile.getParentFile(), "tmp-apk");
    if (tmpWorkDir.exists()) {
        FileUtils.deleteDirectory(tmpWorkDir);
    }
    if (!tmpWorkDir.exists()) {
        tmpWorkDir.mkdirs();
    }

    Map zipEntityMap = new HashMap();
    ZipUtils.unzip(apkFile, tmpWorkDir.getAbsolutePath(), "UTF-8", zipEntityMap, true);

    FileUtils.deleteDirectory(new File(tmpWorkDir, "assets"));
    FileUtils.deleteDirectory(new File(tmpWorkDir, "res"));
    FileUtils.forceDelete(new File(tmpWorkDir, "resources.arsc"));
    FileUtils.forceDelete(new File(tmpWorkDir, "AndroidManifest.xml"));

    File resdir = new File(diffAPkFile.getParentFile(), "tmp-diffResAp");
    resdir.mkdirs();
    ZipUtils.unzip(getResourceFile(), resdir.getAbsolutePath(), "UTF-8", new HashMap<String, ZipEntry>(), true);

    FileUtils.copyDirectory(resdir, tmpWorkDir);
    ZipUtils.rezip(diffAPkFile, tmpWorkDir, zipEntityMap);

    FileUtils.deleteDirectory(tmpWorkDir);
    FileUtils.deleteDirectory(resdir);

}

From source file:edu.ucsb.eucalyptus.storage.fs.FileSystemStorageManager.java

public void deleteObject(String[] backup, String bucket, String object) throws IOException {
    if (backup == null || bucket == null || object == null)
        return;/*from w w  w  .  j  a  va 2 s. c o  m*/

    File oldObjectFile = new File(rootDirectory + FILE_SEPARATOR + bucket + FILE_SEPARATOR + object);
    if (oldObjectFile.exists()) {
        backup[0] = new String(rootDirectory + FILE_SEPARATOR + bucket + FILE_SEPARATOR + object + ".backup");
        File backupFile = new File(backup[0]);
        if (backupFile.exists()) {
            FileUtils.forceDelete(backupFile);
        }
        FileUtils.moveFile(oldObjectFile, backupFile);
    }
}

From source file:edu.lternet.pasta.datapackagemanager.DataPackageArchive.java

/**
 * Deletes the data package archive from the local file system.
 * //from  ww  w.ja v  a  2s.c  o  m
 * @param transaction
 *          The transaction identifier of the data package archive.
 * @throws FileNotFoundException
 */
public void deleteDataPackageArchive(String transaction) throws FileNotFoundException {

    String archive = tmpDir + "/" + transaction + ".zip";
    File file = new File(archive);

    if (!file.exists()) {
        String gripe = "The data package archive " + archive + "does exist!";
        throw new FileNotFoundException(gripe);
    } else {
        try {
            FileUtils.forceDelete(file);
        } catch (IOException e) {
            logger.error(e.getMessage());
            e.printStackTrace();
        }
    }

}

From source file:net.rptools.tokentool.controller.ManageOverlays_Controller.java

@FXML
void deleteFolderButton_onAction(ActionEvent event) {
    if (currentDirectory.equals(AppConstants.OVERLAY_DIR))
        return;/*from w  w w  .  j  a v  a 2s.  c  om*/

    if (confirmDelete(currentDirectory)) {
        try {
            FileUtils.forceDelete(currentDirectory);
        } catch (IOException e) {
            log.info("Deleting: " + currentDirectory.getAbsolutePath());
        }

        displayTreeView();
    }
}

From source file:com.silverpeas.util.FileUtil.java

/**
 * Forces the deletion of the specified file. If the write property of the file to delete isn't
 * set, this property is then set before deleting.
 *
 * @param fileToDelete file to delete.//from  w  w w.j  a  va 2s.  co m
 * @throws IOException if the deletion failed or if the file doesn't exist.
 */
public static void forceDeletion(File fileToDelete) throws IOException {
    if (fileToDelete.exists() && !fileToDelete.canWrite()) {
        fileToDelete.setWritable(true);
    }
    FileUtils.forceDelete(fileToDelete);
}