blob: 92dc34d5e8b2daae4adcf5aede72e7b5168d12a8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.task.util.file;
import com.yahoo.vespa.hosted.node.admin.component.TaskContext;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.logging.Logger;
import static com.yahoo.yolean.Exceptions.uncheck;
/**
* Deletes a file or empty directory.
*
* @author hakonhall
*/
public class FileDeleter {
private static final Logger logger = Logger.getLogger(FileDeleter.class.getName());
private final Path path;
public FileDeleter(Path path) {
this.path = path;
}
public boolean converge(TaskContext context) {
boolean deleted = uncheck(() -> Files.deleteIfExists(path));
if (deleted) {
context.recordSystemModification(logger, "Deleted " + path);
}
return deleted;
}
}
|