Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #23. Fix deletion of single result. #71

Merged
merged 5 commits into from
Oct 18, 2018
Merged
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
@@ -219,6 +219,10 @@ public void deleteDirectory(File directory) throws IOException {
FileUtils.deleteDirectory(directory);
}

public boolean deleteQuietly(File file) {
return FileUtils.deleteQuietly(file);
}

public void deleteFile(File file) throws IOException {
Files.delete(file.toPath());
}
49 changes: 27 additions & 22 deletions server/src/main/java/com/graphicsfuzz/server/webui/WebUi.java
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
import com.google.gson.JsonObject;
import com.graphicsfuzz.alphanumcomparator.AlphanumComparator;
import com.graphicsfuzz.common.transformreduce.Constants;
import com.graphicsfuzz.common.util.FileHelper;
import com.graphicsfuzz.common.util.ReductionProgressHelper;
import com.graphicsfuzz.common.util.ShaderJobFileOperations;
import com.graphicsfuzz.reducer.ReductionKind;
@@ -847,7 +848,8 @@ private void viewResult(HttpServletRequest request, HttpServletResponse response
"Status: <b>", status, "</b></p>");

htmlAppendLn("<form method='post' id='deleteForm'>\n",
"<input type='hidden' name='path' value='", variantResultJobFileNoExtension, "'/>\n",
"<input type='hidden' name='path' value='", variantResultJobFileNoExtension + ".info.json",
"'/>\n",
"<input type='hidden' name='type' value='delete'/>\n",
"<input type='hidden' name='num_back' value='2'/>\n",
"<div class='ui button'",
@@ -1290,35 +1292,38 @@ private void compareWorkers(HttpServletRequest request, HttpServletResponse resp
private void delete(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
//Find file
File file = new File(request.getParameter("path"));

final File file = new File(request.getParameter("path"));
final String numBack = request.getParameter("num_back");

if (!file.exists()) {
err404(request, response, "Path to results " + file.getPath() + " not allowed/valid!");
return;
}
String numBack = request.getParameter("num_back");

//Delete file
if (file.isFile()) {
file.delete();
} else if (file.isDirectory()) {
try {
FileUtils.deleteDirectory(file);
} catch (Exception exception) {
err404(request, response, exception.getMessage());
return;
if (file.toString().endsWith(".info.json")) {
fileOps.deleteShaderJobResultFile(file);
// There might also be a reduction result. If so, we delete it.

// E.g. variant_001
final String variantName = FileHelper.removeEnd(file.getName(), ".info.json");
// E.g. shader_family_001_exp
final String expDirName = file.getParentFile().getName();
// E.g. android_phone
final File workerResultDir = file.getParentFile().getParentFile();
if (expDirName.endsWith("_exp")) {
// E.g. shader_family_001
final String shaderFamilyName = FileHelper.removeEnd(expDirName, "_exp");
// E.g. shader_family_001 _ variant_001 _inv
final String reductionDirName = shaderFamilyName + "_" + variantName + "_inv";
// E.g. processing/android_phone/shader_family_001_variant_001 _inv
final File reductionDir = new File(workerResultDir, reductionDirName);
fileOps.deleteQuietly(reductionDir);
}
} else {
FileUtils.forceDelete(file);
}

//Check if successful
if (file.exists()) {
err404(request, response, "Attempt to delete " + file.getPath() + " failed!");
return;
}

String deleteJs = getResourceContent("goBack.js")
+ "\nwindow.onload = goBack('" + file.getPath() + " deleted!', " + numBack + ");";

html.setLength(0);
htmlAppendLn("<script>\n",
getResourceContent("goBack.js"), "\n",