mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-01 05:11:34 +02:00
Fix issue with cloning multiple identical files and add test
This commit is contained in:
@@ -4,12 +4,12 @@ import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import uk.ac.ic.wlgitbridge.data.filestore.RawFile;
|
||||
import uk.ac.ic.wlgitbridge.data.CandidateSnapshot;
|
||||
import uk.ac.ic.wlgitbridge.data.SnapshotFetcher;
|
||||
import uk.ac.ic.wlgitbridge.data.filestore.GitDirectoryContents;
|
||||
import uk.ac.ic.wlgitbridge.data.model.db.PersistentStore;
|
||||
import uk.ac.ic.wlgitbridge.data.filestore.RawDirectory;
|
||||
import uk.ac.ic.wlgitbridge.data.filestore.RawFile;
|
||||
import uk.ac.ic.wlgitbridge.data.model.db.PersistentStore;
|
||||
import uk.ac.ic.wlgitbridge.snapshot.exception.FailedConnectionException;
|
||||
import uk.ac.ic.wlgitbridge.snapshot.getforversion.SnapshotAttachment;
|
||||
import uk.ac.ic.wlgitbridge.snapshot.push.exception.SnapshotPostException;
|
||||
@@ -17,10 +17,7 @@ import uk.ac.ic.wlgitbridge.util.Util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by Winston on 06/11/14.
|
||||
@@ -55,8 +52,9 @@ public class DataStore {
|
||||
for (Snapshot snapshot : snapshots) {
|
||||
List<RawFile> files = new LinkedList<RawFile>();
|
||||
files.addAll(snapshot.getSrcs());
|
||||
Map<String, byte[]> fetchedUrls = new HashMap<String, byte[]>();
|
||||
for (SnapshotAttachment snapshotAttachment : snapshot.getAtts()) {
|
||||
files.add(resourceFetcher.get(name, snapshotAttachment.getUrl(), snapshotAttachment.getPath(), repository));
|
||||
files.add(resourceFetcher.get(name, snapshotAttachment.getUrl(), snapshotAttachment.getPath(), repository, fetchedUrls));
|
||||
}
|
||||
commit(name, new GitDirectoryContents(files, rootGitDirectory, name, snapshot), repository);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import uk.ac.ic.wlgitbridge.util.Util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
@@ -27,16 +28,22 @@ public class ResourceFetcher {
|
||||
this.persistentStore = persistentStore;
|
||||
}
|
||||
|
||||
public RawFile get(String projectName, String url, String newPath, Repository repository) throws IOException {
|
||||
public RawFile get(String projectName, String url, String newPath, Repository repository, Map<String, byte[]> fetchedUrls) throws IOException {
|
||||
String path = persistentStore.getPathForURLInProject(projectName, url);
|
||||
byte[] contents;
|
||||
if (path == null) {
|
||||
path = newPath;
|
||||
contents = fetch(projectName, url, path);
|
||||
fetchedUrls.put(url, contents);
|
||||
} else {
|
||||
Util.sout("Found (" + projectName + "): " + url);
|
||||
Util.sout("At (" + projectName + "): " + path);
|
||||
contents = new RepositoryObjectTreeWalker(repository).getDirectoryContents().getFileTable().get(path).getContents();
|
||||
RawFile rawFile = new RepositoryObjectTreeWalker(repository).getDirectoryContents().getFileTable().get(path);
|
||||
if (rawFile != null) {
|
||||
contents = rawFile.getContents();
|
||||
} else {
|
||||
contents = fetchedUrls.get(url);
|
||||
}
|
||||
}
|
||||
return new RepositoryFile(newPath, contents);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user