From b01ec908e190382984eea804266e89d092fa2fd8 Mon Sep 17 00:00:00 2001 From: Winston Li Date: Sun, 22 Feb 2015 02:24:13 +0000 Subject: [PATCH] Delete url indexes on successful push. --- .../writelatex/CandidateSnapshot.java | 39 +++++++++---------- .../writelatex/model/DataStore.java | 11 ++++-- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/CandidateSnapshot.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/CandidateSnapshot.java index e5b6888e4f..78bafa4200 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/CandidateSnapshot.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/CandidateSnapshot.java @@ -22,11 +22,13 @@ public class CandidateSnapshot { private final String projectName; private final int currentVersion; private final List files; + private final List deleted; public CandidateSnapshot(String projectName, int currentVersion, RawDirectory directoryContents, RawDirectory oldDirectoryContents) { this.projectName = projectName; this.currentVersion = currentVersion; files = diff(directoryContents, oldDirectoryContents); + deleted = deleted(directoryContents, oldDirectoryContents); } private List diff(RawDirectory directoryContents, RawDirectory oldDirectoryContents) { @@ -40,6 +42,19 @@ public class CandidateSnapshot { return files; } + private List deleted(RawDirectory directoryContents, RawDirectory oldDirectoryContents) { + List deleted = new LinkedList(); + Map fileTable = directoryContents.getFileTable(); + for (Entry 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 { File directory = new File(rootGitDirectory, ".wlgb/atts/" + projectName); for (ServletFile file : files) { @@ -80,26 +95,8 @@ public class CandidateSnapshot { return projectName; } -// @Override -// public int getPreviousVersionID() { -// return previousVersionID; -// } -// -// @Override -// public String getProjectURL() { -// return projectURL; -// } -// -// @Override -// public void approveWithVersionID(int versionID) { -// callback.approveSnapshot(versionID, this); -// } -// - -// -// @Override -// public WLDirectoryNode getDirectoryNode() { -// return directoryNode; -// } + public List getDeleted() { + return deleted; + } } diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/model/DataStore.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/model/DataStore.java index 3db75e7d1a..ed5dfb4b19 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/model/DataStore.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/model/DataStore.java @@ -20,6 +20,7 @@ import java.io.File; import java.io.IOException; import java.util.LinkedList; import java.util.List; +import java.util.Set; import java.util.TimeZone; /** @@ -58,20 +59,22 @@ public class DataStore implements CandidateSnapshotCallback { for (SnapshotAttachment snapshotAttachment : snapshot.getAtts()) { 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(); Git git = new Git(repository); - for (String missing : git.status().call().getMissing()) { + Set missingFiles = git.status().call().getMissing(); + for (String missing : missingFiles) { git.rm().setCached(true).addFilepattern(missing).call(); } git.add().addFilepattern(".").call(); git.commit().setAuthor(new PersonIdent(contents.getUserName(), contents.getUserEmail(), contents.getWhen(), TimeZone.getDefault())) .setMessage(contents.getCommitMessage()) .call(); + persistentStore.deleteFilesForProject(name, missingFiles.toArray(new String[missingFiles.size()])); Util.deleteInDirectoryApartFrom(contents.getDirectory(), ".git"); } @@ -86,7 +89,9 @@ public class DataStore implements CandidateSnapshotCallback { @Override public void approveSnapshot(int versionID, CandidateSnapshot candidateSnapshot) { + List deleted = candidateSnapshot.getDeleted(); persistentStore.setLatestVersionForProject(candidateSnapshot.getProjectName(), versionID); + persistentStore.deleteFilesForProject(candidateSnapshot.getProjectName(), deleted.toArray(new String[deleted.size()])); } private File initRootGitDirectory(String rootGitDirectoryPath) {