Attempts to manually delete data in the output path. If this fails, another delete attempt is
made on JVM shutdown.

@param context the job content to cleanup.
@throws IOException if a FileSystem exception is encountered.
354078
protected void cleanup(JobContext context) throws IOException {
    boolean delete =
        BigQueryOutputConfiguration.getCleanupTemporaryDataFlag(context.getConfiguration());

    if (delete && outputFileSystem.exists(outputPath)) {
      logger.atInfo().log("Found GCS output data at '%s', attempting to clean up.", outputPath);
      if (outputFileSystem.delete(outputPath, true)) {
        logger.atInfo().log("Successfully deleted GCS output path '%s'.", outputPath);
      } else {
        logger.atWarning().log(
            "Failed to delete GCS output at '%s', retrying on shutdown.", outputPath);
        outputFileSystem.deleteOnExit(outputPath);
      }
    }
  }
1029890
@Override
    public void delete(final Path path) throws IOException {

        assert path != null : "Path must be specified";
        final Archive<?> archive = this.getArchive(path);
        final String pathString = path.toString();
        if (!archive.contains(pathString)) {
            throw new NoSuchFileException(path + " does not exist in " + archive);
        }
        final boolean isDirectory = archive.get(pathString).getAsset() == null;

        // Directory?
        if (isDirectory) {
            // Check empty?
            if (!archive.getContent(new org.jboss.shrinkwrap.api.Filter<ArchivePath>() {
                @Override
                public boolean include(final ArchivePath path) {
                    final String filterPathString = path.get();
                    return filterPathString.startsWith(pathString) && !filterPathString.equals(pathString);
                }
            }).isEmpty()) {
                throw new DirectoryNotEmptyException(pathString);
            }
        }
        archive.delete(pathString);
        if (log.isLoggable(Level.FINEST)) {
            log.finest("Deleted " + path.toString() + " from " + archive.toString());
        }
    }
224556
private void tearDown() throws Exception {
    try {
      if (fileSystem != null) {
        fileSystem.delete(new Path(ROOT), true, true);
      }
    } finally {
      RPC.stopProxy(proxyClientProxyProtocol);
      IOUtils.cleanup(LOG, proxyTClientProxyProtocol, clientManager, fileSystem);
    }
  }
1179281
public void deleteFile(JimfsPath path, DeleteMode deleteMode) throws IOException {
    store.writeLock().lock();
    try {
      DirectoryEntry entry = lookUp(path, Options.NOFOLLOW_LINKS).requireExists(path);
      delete(entry, deleteMode, path);
    } finally {
      store.writeLock().unlock();
    }
  }
396865
private static boolean deleteRecursivelyIfExists(HdfsContext context, HdfsEnvironment hdfsEnvironment, Path path)
    {
        FileSystem fileSystem;
        try {
            fileSystem = hdfsEnvironment.getFileSystem(context, path);
        }
        catch (IOException ignored) {
            return false;
        }

        return deleteIfExists(fileSystem, path, true);
    }
537201
public void run(Context context) throws IOException, InterruptedException {
    setup(context);
    while (context.nextKey()) {
      context.progress();
      reduce(context.getCurrentKey(), context.getValues(), context);
    }
    cleanup(context);
  }
1222999
private void cleanupWorkingDirectory() throws IOException {
    LOGGER.info("Deleting persisted work units for job " + this.jobContext.getJobId());
    stateStores.getWuStateStore().delete(this.jobContext.getJobId());

    // delete the directory that stores the task state files
    stateStores.getTaskStateStore().delete(outputTaskStateDir.getName());

    LOGGER.info("Deleting job state file for job " + this.jobContext.getJobId());

    if (this.stateStores.haveJobStateStore()) {
      this.stateStores.getJobStateStore().delete(this.jobContext.getJobId());
    } else {
      Path jobStateFilePath = GobblinClusterUtils.getJobStateFilePath(false, this.appWorkDir, this.jobContext.getJobId());
      this.fs.delete(jobStateFilePath, false);
    }
  }
968789
public static void deleteIfExists(FileSystem fs, Path path, boolean recursive) throws IOException {
    if (fs.exists(path)) {
      deletePath(fs, path, recursive);
    }
  }
52874
public static void deletePath(FileSystem fs, Path f, boolean recursive) throws IOException {
    if (fs.exists(f) && !fs.delete(f, recursive)) {
      throw new IOException("Failed to delete: " + f);
    }
  }
131017
@Override
	public synchronized void removeContext(Context context) {

        if( log.isDebugEnabled() )
            log.debug("Removing context[" + context.getPath() + "]");

        boolean isContextExists = isContextExists(context);
        if(!isContextExists)
        	return;
        
        // Remove this Context from the associated Host
        if( log.isDebugEnabled() )
            log.debug(" Removing this Context");
        context.getParent().removeChild(context);

    }
1160341
protected FtpMessage deleteFile(DeleteCommand delete, TestContext context) {
        String remoteFilePath = context.replaceDynamicContentInString(delete.getTarget().getPath());

        try {
            if (!StringUtils.hasText(remoteFilePath)) {
                return null;
            }

            boolean success = true;
            if (isDirectory(remoteFilePath)) {
                if (!ftpClient.changeWorkingDirectory(remoteFilePath)) {
                    throw new CitrusRuntimeException("Failed to change working directory to " + remoteFilePath + ". FTP reply code: " + ftpClient.getReplyString());
                }

                if (delete.isRecursive()) {
                    FTPFile[] ftpFiles = ftpClient.listFiles();
                    for (FTPFile ftpFile : ftpFiles) {
                        DeleteCommand recursiveDelete = new DeleteCommand();
                        DeleteCommand.Target target = new DeleteCommand.Target();
                        target.setPath(remoteFilePath + "/" + ftpFile.getName());
                        recursiveDelete.setTarget(target);
                        recursiveDelete.setIncludeCurrent(true);
                        deleteFile(recursiveDelete, context);
                    }
                }

                if (delete.isIncludeCurrent()) {
                    // we cannot delete the current working directory, so go to root directory and delete from there
                    ftpClient.changeWorkingDirectory("/");
                    success = ftpClient.removeDirectory(remoteFilePath);
                }
            } else {
                success = ftpClient.deleteFile(remoteFilePath);
            }

            if (!success) {
                throw new CitrusRuntimeException("Failed to delete path " + remoteFilePath + ". FTP reply code: " + ftpClient.getReplyString());
            }
        } catch (IOException e) {
            throw new CitrusRuntimeException("Failed to delete file from FTP server", e);
        }

        // If there was no file to delete, the ftpClient has the reply code from the previously executed
        // operation. Since we want to have a deterministic behaviour, we need to set the reply code and
        // reply string on our own!
        if (ftpClient.getReplyCode() != FILE_ACTION_OK) {
            return FtpMessage.deleteResult(FILE_ACTION_OK, String.format("%s No files to delete.", FILE_ACTION_OK), true);
        }
        return FtpMessage.deleteResult(ftpClient.getReplyCode(), ftpClient.getReplyString(), isPositive(ftpClient.getReplyCode()));
    }
265297
@Override
  public synchronized void close() throws IOException {
    // TODO(zac) Determine the behavior when closing the context during operations.
    if (!mClosed) {
      mClosed = true;
      if (mCachingEnabled) {
        Factory.FILESYSTEM_CACHE.remove(new FileSystemKey(mFsContext.getClientContext()));
      }
      mFsContext.close();
    }
  }
487913
@Override
  public void abortTask(TaskAttemptContext context) throws IOException {
    try {
      if (workPath != null) { 
        context.progress();
        if (!outputFileSystem.delete(workPath, true)) {
          LOG.warn("Deleting output in " + workPath + " returns false");
        }
      }
    } catch (IOException ie) {
      LOG.warn("Error discarding output in " + workPath, ie);
      throw ie;
    }
  }
655793
public static void delete(FileSystem fs, String name) throws IOException {
    Path dir = new Path(name);
    Path data = new Path(dir, DATA_FILE_NAME);
    Path index = new Path(dir, INDEX_FILE_NAME);

    fs.delete(data, true);
    fs.delete(index, true);
    fs.delete(dir, true);
  }
1236826
@Override
	public synchronized void delete(int contextId, int type, String data) throws DatabaseException {
    	try {
			psDeleteData.setInt(1, contextId);
			psDeleteData.setInt(2, type);
			psDeleteData.setString(3, data);
			psDeleteData.executeUpdate();
		} catch (SQLException e) {
			throw new DatabaseException(e);
		}
    }
609180
@Override
	public void close() throws IOException {
		if (this.in != null) {
			this.in.close();
		}
		if (!this.tempFile.delete()) {
			LOG.warn("Cannot delete tempFile: " + this.tempFile.getAbsolutePath());
			throw new IOException("Cannot delete tempFile: " + this.tempFile.getAbsolutePath());
		}
		;
	}
117150
@Override
  public void abortJob(JobContext context, State state) throws IOException {
    super.abortJob(context, state);
    cleanup(context);
  }