Skip to content

Commit

Permalink
Merge pull request #246 from thusithathilina/release-2.0.0
Browse files Browse the repository at this point in the history
WMS-81: Improve temp file deleting strategy with FormParam
  • Loading branch information
thusithathilina authored Jul 21, 2016
2 parents c141416 + 8f84558 commit 963822e
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.common.base.Preconditions;
import org.apache.commons.io.FileCleaningTracker;
import org.apache.commons.io.FileDeleteStrategy;
import org.wso2.msf4j.HttpStreamer;
import org.wso2.msf4j.Request;
import org.wso2.msf4j.Response;
Expand Down Expand Up @@ -160,10 +161,6 @@ private void createObject(Request request, Object[] args, int idx, HttpResourceM

private Object getFormDataParamValue(HttpResourceModel.ParameterInfo<List<Object>> paramInfo, Request request)
throws FormUploadException, IOException {
if (Files.notExists(tempRepoPath)) {
Files.createDirectory(tempRepoPath);
}

Type paramType = paramInfo.getParameterType();
FormDataParam formDataParam = paramInfo.getAnnotation();
if (getFormParameters() == null) {
Expand Down Expand Up @@ -267,12 +264,16 @@ private Object createBean(List<Object> parameter, FormDataParam formDataParam, T

private File createAndTrackTempFile(FormItem item) throws IOException {
if (tmpPathForRequest == null) {
if (Files.notExists(tempRepoPath)) {
Files.createDirectory(tempRepoPath);
}
tmpPathForRequest = Files.createTempDirectory(tempRepoPath, "tmp");
}
Path path = Paths.get(tmpPathForRequest.toString(), item.getName());
File file = path.toFile();
StreamUtil.copy(item.openStream(), new FileOutputStream(file), true);
fileCleaningTracker.track(file, file);
fileCleaningTracker.track(tmpPathForRequest.toFile(), file, FileDeleteStrategy.FORCE);
return file;
}

Expand Down

0 comments on commit 963822e

Please sign in to comment.