Delete url indexes on successful push.

This commit is contained in:
Winston Li 2015-02-22 02:24:13 +00:00
parent 70d9c0e31d
commit b01ec908e1
2 changed files with 26 additions and 24 deletions

View file

@ -22,11 +22,13 @@ public class CandidateSnapshot {
private final String projectName;
private final int currentVersion;
private final List<ServletFile> files;
private final List<String> 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<ServletFile> diff(RawDirectory directoryContents, RawDirectory oldDirectoryContents) {
@ -40,6 +42,19 @@ public class CandidateSnapshot {
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 {
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<String> getDeleted() {
return deleted;
}
}

View file

@ -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<String> 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<String> deleted = candidateSnapshot.getDeleted();
persistentStore.setLatestVersionForProject(candidateSnapshot.getProjectName(), versionID);
persistentStore.deleteFilesForProject(candidateSnapshot.getProjectName(), deleted.toArray(new String[deleted.size()]));
}
private File initRootGitDirectory(String rootGitDirectoryPath) {