Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import java.io.InputStream;
import java.io.OutputStream;
import org.glassfish.hk2.utilities.CleanerFactory;

import java.lang.ref.Cleaner;
import java.net.URI;
import java.sql.SQLException;
import java.util.ArrayList;
Expand Down Expand Up @@ -290,16 +292,22 @@ protected void postProcessParts() {
*/
public static class Temp extends PayloadFilesManager {

// /*
// * regex to match colons and backslashes on Windows and slashes on non-Windows
// */
// private static final String DIR_PATH_TO_FLAT_NAME_PATTERN = (File.separatorChar == '\\') ?
// "[:\\\\]" : "/";
private final Cleaner.Cleanable cleanable;

static class CleanableTempPayloadFilesManagerState implements Runnable {

private final File targetDir;

private boolean isCleanedUp = false;
CleanableTempPayloadFilesManagerState(File targetDir) {
this.targetDir = targetDir;
}

// /** maps payload part name paths (excluding name and type) to temp file subdirs */
// private Map<String,File> pathToTempSubdir = new HashMap<String,File>();
@Override
public void run() {
FileUtils.whack(this.targetDir);
}

}

public Temp(final File parentDir, final ActionReport report,
final Logger logger) throws IOException {
Expand All @@ -308,7 +316,8 @@ public Temp(final File parentDir, final ActionReport report,
logger),
report,
logger);
registerCleanupEvent();
CleanableTempPayloadFilesManagerState state = new CleanableTempPayloadFilesManagerState(super.targetDir);
this.cleanable = CleanerFactory.create().register(this, state);
}
/**
* Creates a new PayloadFilesManager for temporary files.
Expand All @@ -333,16 +342,7 @@ public Temp(final Logger logger) throws IOException {
* Deletes the temporary files created by this temp PayloadFilesManager.
*/
public void cleanup() {
if ( ! isCleanedUp) {
FileUtils.whack(super.targetDir);
isCleanedUp = true;
}
}

public final void registerCleanupEvent() {
CleanerFactory.create().register(this, () -> {
cleanup();
});
this.cleanable.clean();
}

@Override
Expand Down