mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Delete url indexes on successful push.
This commit is contained in:
parent
70d9c0e31d
commit
b01ec908e1
2 changed files with 26 additions and 24 deletions
|
@ -22,11 +22,13 @@ public class CandidateSnapshot {
|
||||||
private final String projectName;
|
private final String projectName;
|
||||||
private final int currentVersion;
|
private final int currentVersion;
|
||||||
private final List<ServletFile> files;
|
private final List<ServletFile> files;
|
||||||
|
private final List<String> deleted;
|
||||||
|
|
||||||
public CandidateSnapshot(String projectName, int currentVersion, RawDirectory directoryContents, RawDirectory oldDirectoryContents) {
|
public CandidateSnapshot(String projectName, int currentVersion, RawDirectory directoryContents, RawDirectory oldDirectoryContents) {
|
||||||
this.projectName = projectName;
|
this.projectName = projectName;
|
||||||
this.currentVersion = currentVersion;
|
this.currentVersion = currentVersion;
|
||||||
files = diff(directoryContents, oldDirectoryContents);
|
files = diff(directoryContents, oldDirectoryContents);
|
||||||
|
deleted = deleted(directoryContents, oldDirectoryContents);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ServletFile> diff(RawDirectory directoryContents, RawDirectory oldDirectoryContents) {
|
private List<ServletFile> diff(RawDirectory directoryContents, RawDirectory oldDirectoryContents) {
|
||||||
|
@ -40,6 +42,19 @@ public class CandidateSnapshot {
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<String> deleted(RawDirectory directoryContents, RawDirectory oldDirectoryContents) {
|
||||||
|
List<String> deleted = new LinkedList<String>();
|
||||||
|
Map<String, RawFile> fileTable = directoryContents.getFileTable();
|
||||||
|
for (Entry<String, RawFile> entry : oldDirectoryContents.getFileTable().entrySet()) {
|
||||||
|
String path = entry.getKey();
|
||||||
|
RawFile newFile = fileTable.get(path);
|
||||||
|
if (newFile == null) {
|
||||||
|
deleted.add(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return deleted;
|
||||||
|
}
|
||||||
|
|
||||||
public void writeServletFiles(File rootGitDirectory) throws IOException {
|
public void writeServletFiles(File rootGitDirectory) throws IOException {
|
||||||
File directory = new File(rootGitDirectory, ".wlgb/atts/" + projectName);
|
File directory = new File(rootGitDirectory, ".wlgb/atts/" + projectName);
|
||||||
for (ServletFile file : files) {
|
for (ServletFile file : files) {
|
||||||
|
@ -80,26 +95,8 @@ public class CandidateSnapshot {
|
||||||
return projectName;
|
return projectName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
public List<String> getDeleted() {
|
||||||
// public int getPreviousVersionID() {
|
return deleted;
|
||||||
// return previousVersionID;
|
}
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public String getProjectURL() {
|
|
||||||
// return projectURL;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void approveWithVersionID(int versionID) {
|
|
||||||
// callback.approveSnapshot(versionID, this);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public WLDirectoryNode getDirectoryNode() {
|
|
||||||
// return directoryNode;
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,20 +59,22 @@ public class DataStore implements CandidateSnapshotCallback {
|
||||||
for (SnapshotAttachment snapshotAttachment : snapshot.getAtts()) {
|
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));
|
||||||
}
|
}
|
||||||
commit(new GitDirectoryContents(files, rootGitDirectory, name, snapshot), repository);
|
commit(name, new GitDirectoryContents(files, rootGitDirectory, name, snapshot), repository);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void commit(GitDirectoryContents contents, Repository repository) throws IOException, GitAPIException {
|
private void commit(String name, GitDirectoryContents contents, Repository repository) throws IOException, GitAPIException {
|
||||||
contents.write();
|
contents.write();
|
||||||
Git git = new Git(repository);
|
Git git = new Git(repository);
|
||||||
for (String missing : git.status().call().getMissing()) {
|
Set<String> missingFiles = git.status().call().getMissing();
|
||||||
|
for (String missing : missingFiles) {
|
||||||
git.rm().setCached(true).addFilepattern(missing).call();
|
git.rm().setCached(true).addFilepattern(missing).call();
|
||||||
}
|
}
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
git.commit().setAuthor(new PersonIdent(contents.getUserName(), contents.getUserEmail(), contents.getWhen(), TimeZone.getDefault()))
|
git.commit().setAuthor(new PersonIdent(contents.getUserName(), contents.getUserEmail(), contents.getWhen(), TimeZone.getDefault()))
|
||||||
.setMessage(contents.getCommitMessage())
|
.setMessage(contents.getCommitMessage())
|
||||||
.call();
|
.call();
|
||||||
|
persistentStore.deleteFilesForProject(name, missingFiles.toArray(new String[missingFiles.size()]));
|
||||||
Util.deleteInDirectoryApartFrom(contents.getDirectory(), ".git");
|
Util.deleteInDirectoryApartFrom(contents.getDirectory(), ".git");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +89,9 @@ public class DataStore implements CandidateSnapshotCallback {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void approveSnapshot(int versionID, CandidateSnapshot candidateSnapshot) {
|
public void approveSnapshot(int versionID, CandidateSnapshot candidateSnapshot) {
|
||||||
|
List<String> deleted = candidateSnapshot.getDeleted();
|
||||||
persistentStore.setLatestVersionForProject(candidateSnapshot.getProjectName(), versionID);
|
persistentStore.setLatestVersionForProject(candidateSnapshot.getProjectName(), versionID);
|
||||||
|
persistentStore.deleteFilesForProject(candidateSnapshot.getProjectName(), deleted.toArray(new String[deleted.size()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
private File initRootGitDirectory(String rootGitDirectoryPath) {
|
private File initRootGitDirectory(String rootGitDirectoryPath) {
|
||||||
|
|
Loading…
Reference in a new issue