Skip to content

Commit

Permalink
Add privileges for removing files (#45)
Browse files Browse the repository at this point in the history
Signed-off-by: Sruti Parthiban <partsrut@amazon.com>
  • Loading branch information
sruti1312 authored Aug 17, 2021
1 parent 63cd019 commit 2cbc697
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ private void readInternal(Path pathToFile, int bufferSize, EventDispatcher proce
}

public void deleteAllFiles() {
LOG.debug("Cleaning up any leftover files.");
Util.invokePrivileged(this::deleteAllFilesWithPrivilege);
}

public void deleteAllFilesWithPrivilege() {
LOG.debug("Cleaning up any leftover files in [{}]", metricsLocation);
File root = new File(metricsLocation);
String[] filesToDelete = root.list();
if (filesToDelete == null) {
Expand All @@ -202,7 +206,7 @@ public void deleteFiles(List<String> filesToDelete) {
File root = new File(metricsLocation);
for (String fileToDelete : filesToDelete) {
File file = new File(root, fileToDelete);
PerformanceAnalyzerMetrics.removeMetrics(file);
removeFilesWithPrivilege(file);
filesDeletedCount += 1;
}
long duration = System.currentTimeMillis() - startTime;
Expand All @@ -212,4 +216,8 @@ public void deleteFiles(List<String> filesToDelete) {
WriterMetrics.EVENT_LOG_FILES_DELETED, "", filesDeletedCount);
LOG.debug("'{}' Old writer files cleaned up.", filesDeletedCount);
}

public void removeFilesWithPrivilege(File file) {
Util.invokePrivileged(() -> PerformanceAnalyzerMetrics.removeMetrics(file));
}
}

0 comments on commit 2cbc697

Please sign in to comment.