Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

Commit

Permalink
Proper cleanup of a single trace file folder
Browse files Browse the repository at this point in the history
Reviewed By: simpleton

Differential Revision: D37825765

fbshipit-source-id: a1fe26289b1d159918842d414e36f4b8010f7b5b
  • Loading branch information
aandreyeu authored and facebook-github-bot committed Jul 13, 2022
1 parent e055ce7 commit 33b50bc
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions java/main/com/facebook/profilo/core/TraceOrchestrator.java
Original file line number Diff line number Diff line change
Expand Up @@ -493,29 +493,34 @@ public void onTraceWriteEnd(TraceContext trace) {
}

private void handleZipAndUpload(TraceContext trace) {
File uploadFile;
File uploadFile = null;
if (ZipHelper.shouldZipDirectory(trace.folder)) {
uploadFile =
File traceFile =
ZipHelper.getCompressedFile(trace.folder, ZipHelper.ZIP_SUFFIX + ZipHelper.TMP_SUFFIX);

// Add a timestamp to the file so that the FileManager's trimming rules
// work fine (see trimFolderByFileCount)
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH-mm-ss", Locale.US);
String timestamp = dateFormat.format(new Date());
File fileWithTimestamp =
new File(uploadFile.getParentFile(), timestamp + "-" + uploadFile.getName());
if (uploadFile.renameTo(fileWithTimestamp)) {
new File(traceFile.getParentFile(), timestamp + "-" + traceFile.getName());
if (traceFile.renameTo(fileWithTimestamp)) {
uploadFile = fileWithTimestamp;
}
deleteDirectory(trace.folder);
} else {
File[] fileList = trace.folder.listFiles();
if (fileList == null || fileList.length == 0) {
return;
}
uploadFile = fileList[0];
File traceFile = fileList[0];
// Move the trace file up to the base folder
File targetTraceFile = new File(trace.folder.getParentFile(), traceFile.getName());
if (traceFile.renameTo(targetTraceFile)) {
uploadFile = targetTraceFile;
}
}
if (uploadFile == null) {
// Unable to prepare trace file for processing
return;
}

Expand Down

0 comments on commit 33b50bc

Please sign in to comment.