mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Exception to handle files too big to be processed
This commit is contained in:
parent
1e845bafc2
commit
7048032463
5 changed files with 55 additions and 7 deletions
|
@ -53,7 +53,7 @@ public class DataStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeCommitsFromSnapshots(String name, Repository repository, List<Snapshot> snapshots) throws IOException, GitAPIException {
|
private void makeCommitsFromSnapshots(String name, Repository repository, List<Snapshot> snapshots) throws IOException, GitAPIException, SnapshotPostException {
|
||||||
for (Snapshot snapshot : snapshots) {
|
for (Snapshot snapshot : snapshots) {
|
||||||
List<RawFile> files = new LinkedList<RawFile>();
|
List<RawFile> files = new LinkedList<RawFile>();
|
||||||
files.addAll(snapshot.getSrcs());
|
files.addAll(snapshot.getSrcs());
|
||||||
|
|
|
@ -10,6 +10,7 @@ import uk.ac.ic.wlgitbridge.data.model.db.PersistentStore;
|
||||||
import uk.ac.ic.wlgitbridge.git.util.RepositoryObjectTreeWalker;
|
import uk.ac.ic.wlgitbridge.git.util.RepositoryObjectTreeWalker;
|
||||||
import uk.ac.ic.wlgitbridge.snapshot.base.Request;
|
import uk.ac.ic.wlgitbridge.snapshot.base.Request;
|
||||||
import uk.ac.ic.wlgitbridge.snapshot.exception.FailedConnectionException;
|
import uk.ac.ic.wlgitbridge.snapshot.exception.FailedConnectionException;
|
||||||
|
import uk.ac.ic.wlgitbridge.snapshot.push.exception.SnapshotPostException;
|
||||||
import uk.ac.ic.wlgitbridge.util.Util;
|
import uk.ac.ic.wlgitbridge.util.Util;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
@ -28,7 +29,7 @@ public class ResourceFetcher {
|
||||||
this.persistentStore = persistentStore;
|
this.persistentStore = persistentStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RawFile get(String projectName, String url, String newPath, Repository repository, Map<String, byte[]> fetchedUrls) throws IOException {
|
public RawFile get(String projectName, String url, String newPath, Repository repository, Map<String, byte[]> fetchedUrls) throws IOException, SnapshotPostException {
|
||||||
String path = persistentStore.getPathForURLInProject(projectName, url);
|
String path = persistentStore.getPathForURLInProject(projectName, url);
|
||||||
byte[] contents;
|
byte[] contents;
|
||||||
if (path == null) {
|
if (path == null) {
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package uk.ac.ic.wlgitbridge.git.exception;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import uk.ac.ic.wlgitbridge.snapshot.push.exception.SnapshotPostException;
|
||||||
|
import uk.ac.ic.wlgitbridge.util.Util;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SizeLimitExceededException extends SnapshotPostException {
|
||||||
|
|
||||||
|
private static String path = null;
|
||||||
|
|
||||||
|
public SizeLimitExceededException(String path) {
|
||||||
|
super();
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return "file too big";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getDescriptionLines() {
|
||||||
|
String filename = path != null ? "File '" + path + "' is" : "There's a file";
|
||||||
|
return Arrays.asList(
|
||||||
|
filename + " too large to push to " + Util.getServiceName() + " via git",
|
||||||
|
"the recommended maximum file size is 15MiB"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromJSON(JsonElement json) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -89,13 +89,13 @@ public class WriteLatexPutHook implements PreReceiveHook {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private RawDirectory getPushedDirectoryContents(Repository repository, ReceiveCommand receiveCommand) throws IOException {
|
private RawDirectory getPushedDirectoryContents(Repository repository, ReceiveCommand receiveCommand) throws IOException, SnapshotPostException {
|
||||||
return new RepositoryObjectTreeWalker(repository,
|
return new RepositoryObjectTreeWalker(repository,
|
||||||
receiveCommand.getNewId())
|
receiveCommand.getNewId())
|
||||||
.getDirectoryContents();
|
.getDirectoryContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
private RawDirectory getOldDirectoryContents(Repository repository) throws IOException {
|
private RawDirectory getOldDirectoryContents(Repository repository) throws IOException, SnapshotPostException {
|
||||||
return new RepositoryObjectTreeWalker(repository).getDirectoryContents();
|
return new RepositoryObjectTreeWalker(repository).getDirectoryContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package uk.ac.ic.wlgitbridge.git.util;
|
package uk.ac.ic.wlgitbridge.git.util;
|
||||||
|
|
||||||
|
import org.eclipse.jgit.errors.LargeObjectException;
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
import org.eclipse.jgit.lib.Repository;
|
import org.eclipse.jgit.lib.Repository;
|
||||||
import org.eclipse.jgit.revwalk.RevWalk;
|
import org.eclipse.jgit.revwalk.RevWalk;
|
||||||
|
@ -7,6 +8,8 @@ import org.eclipse.jgit.treewalk.TreeWalk;
|
||||||
import uk.ac.ic.wlgitbridge.data.filestore.RawDirectory;
|
import uk.ac.ic.wlgitbridge.data.filestore.RawDirectory;
|
||||||
import uk.ac.ic.wlgitbridge.data.filestore.RawFile;
|
import uk.ac.ic.wlgitbridge.data.filestore.RawFile;
|
||||||
import uk.ac.ic.wlgitbridge.data.filestore.RepositoryFile;
|
import uk.ac.ic.wlgitbridge.data.filestore.RepositoryFile;
|
||||||
|
import uk.ac.ic.wlgitbridge.git.exception.SizeLimitExceededException;
|
||||||
|
import uk.ac.ic.wlgitbridge.snapshot.push.exception.SnapshotPostException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -33,7 +36,7 @@ public class RepositoryObjectTreeWalker {
|
||||||
this(repository, repository.resolve("HEAD~" + fromHead));
|
this(repository, repository.resolve("HEAD~" + fromHead));
|
||||||
}
|
}
|
||||||
|
|
||||||
public RawDirectory getDirectoryContents() throws IOException {
|
public RawDirectory getDirectoryContents() throws IOException, SnapshotPostException {
|
||||||
return new RawDirectory(walkGitObjectTree());
|
return new RawDirectory(walkGitObjectTree());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,14 +51,21 @@ public class RepositoryObjectTreeWalker {
|
||||||
return treeWalk;
|
return treeWalk;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, RawFile> walkGitObjectTree() throws IOException {
|
private Map<String, RawFile> walkGitObjectTree() throws IOException, SnapshotPostException {
|
||||||
Map<String, RawFile> fileContentsTable = new HashMap<String, RawFile>();
|
Map<String, RawFile> fileContentsTable = new HashMap<String, RawFile>();
|
||||||
if (treeWalk == null) {
|
if (treeWalk == null) {
|
||||||
return fileContentsTable;
|
return fileContentsTable;
|
||||||
}
|
}
|
||||||
while (treeWalk.next()) {
|
while (treeWalk.next()) {
|
||||||
String path = treeWalk.getPathString();
|
String path = treeWalk.getPathString();
|
||||||
fileContentsTable.put(path, new RepositoryFile(path, repository.open(treeWalk.getObjectId(0)).getBytes()));
|
|
||||||
|
try {
|
||||||
|
byte[] content = repository.open(treeWalk.getObjectId(0)).getBytes();
|
||||||
|
fileContentsTable.put(path, new RepositoryFile(path, content));
|
||||||
|
}
|
||||||
|
catch (LargeObjectException e) {
|
||||||
|
throw new SizeLimitExceededException(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return fileContentsTable;
|
return fileContentsTable;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue