mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Use UUID in file url, not (encoded) file path.
This fixes a bunch of issues where funny characters in the file path (spaces, unicode, etc) would cause the file server in this process to respond with a 404 when asked for the file. The 404 would then cause the push to fail. Now we just use a UUID as an opaque and unambiguous identifier for each file.
This commit is contained in:
parent
1e3b973d9a
commit
88adce3a02
3 changed files with 13 additions and 16 deletions
|
@ -5,13 +5,10 @@ import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import uk.ac.ic.wlgitbridge.data.filestore.RawFile;
|
import uk.ac.ic.wlgitbridge.data.filestore.RawFile;
|
||||||
import uk.ac.ic.wlgitbridge.data.filestore.RawDirectory;
|
import uk.ac.ic.wlgitbridge.data.filestore.RawDirectory;
|
||||||
import uk.ac.ic.wlgitbridge.util.Log;
|
|
||||||
import uk.ac.ic.wlgitbridge.util.Util;
|
import uk.ac.ic.wlgitbridge.util.Util;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -80,7 +77,7 @@ public class CandidateSnapshot implements AutoCloseable {
|
||||||
);
|
);
|
||||||
for (ServletFile file : files) {
|
for (ServletFile file : files) {
|
||||||
if (file.isChanged()) {
|
if (file.isChanged()) {
|
||||||
file.writeToDisk(attsDirectory);
|
file.writeToDiskWithName(attsDirectory, file.getUniqueIdentifier());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,16 +115,8 @@ public class CandidateSnapshot implements AutoCloseable {
|
||||||
JsonObject jsonFile = new JsonObject();
|
JsonObject jsonFile = new JsonObject();
|
||||||
jsonFile.addProperty("name", file.getPath());
|
jsonFile.addProperty("name", file.getPath());
|
||||||
if (file.isChanged()) {
|
if (file.isChanged()) {
|
||||||
String path = file.getPath();
|
String identifier = file.getUniqueIdentifier();
|
||||||
String encodedPath;
|
String url = projectURL + "/" + identifier + "?key=" + postbackKey;
|
||||||
try {
|
|
||||||
encodedPath = URLEncoder.encode(path, "UTF-8");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
// This should never happen
|
|
||||||
Log.error("Error while encoding file path: projectUrl={}, path={}", projectURL, path, e);
|
|
||||||
encodedPath = path;
|
|
||||||
}
|
|
||||||
String url = projectURL + "/" + encodedPath + "?key=" + postbackKey;
|
|
||||||
jsonFile.addProperty("url", url);
|
jsonFile.addProperty("url", url);
|
||||||
}
|
}
|
||||||
return jsonFile;
|
return jsonFile;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package uk.ac.ic.wlgitbridge.data;
|
package uk.ac.ic.wlgitbridge.data;
|
||||||
|
|
||||||
import uk.ac.ic.wlgitbridge.data.filestore.RawFile;
|
import uk.ac.ic.wlgitbridge.data.filestore.RawFile;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Winston on 21/02/15.
|
* Created by Winston on 21/02/15.
|
||||||
|
@ -9,12 +10,16 @@ public class ServletFile extends RawFile {
|
||||||
|
|
||||||
private final RawFile file;
|
private final RawFile file;
|
||||||
private final boolean changed;
|
private final boolean changed;
|
||||||
|
private String uuid;
|
||||||
|
|
||||||
public ServletFile(RawFile file, RawFile oldFile) {
|
public ServletFile(RawFile file, RawFile oldFile) {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
|
this.uuid = UUID.randomUUID().toString();
|
||||||
changed = !equals(oldFile);
|
changed = !equals(oldFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUniqueIdentifier() { return uuid; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
return file.getPath();
|
return file.getPath();
|
||||||
|
@ -38,5 +43,4 @@ public class ServletFile extends RawFile {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getPath();
|
return getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,11 @@ public abstract class RawFile {
|
||||||
public abstract long size();
|
public abstract long size();
|
||||||
|
|
||||||
public final void writeToDisk(File directory) throws IOException {
|
public final void writeToDisk(File directory) throws IOException {
|
||||||
File file = new File(directory, getPath());
|
writeToDiskWithName(directory, getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void writeToDiskWithName(File directory, String name) throws IOException {
|
||||||
|
File file = new File(directory, name);
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
OutputStream out = new FileOutputStream(file);
|
OutputStream out = new FileOutputStream(file);
|
||||||
|
|
Loading…
Reference in a new issue