Now deleting all files before writing snapshot to disk.

This commit is contained in:
Winston Li 2014-11-17 12:47:59 +00:00
parent 1e8d7d5840
commit 3bbef6f066
2 changed files with 13 additions and 0 deletions

View file

@ -3,6 +3,7 @@ package uk.ac.ic.wlgitbridge.writelatex.filestore;
import uk.ac.ic.wlgitbridge.bridge.WritableRepositoryContents; import uk.ac.ic.wlgitbridge.bridge.WritableRepositoryContents;
import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException; import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
import uk.ac.ic.wlgitbridge.writelatex.filestore.node.FileNode; import uk.ac.ic.wlgitbridge.writelatex.filestore.node.FileNode;
import uk.ac.ic.wlgitbridge.writelatex.filestore.store.WLFileStore;
import uk.ac.ic.wlgitbridge.writelatex.model.Snapshot; import uk.ac.ic.wlgitbridge.writelatex.model.Snapshot;
import java.io.File; import java.io.File;
@ -30,6 +31,7 @@ public class GitDirectoryContents implements WritableRepositoryContents {
@Override @Override
public void write() throws IOException, FailedConnectionException { public void write() throws IOException, FailedConnectionException {
WLFileStore.deleteInDirectoryApartFrom(gitDirectory, ".git");
for (FileNode fileNode : fileNodes) { for (FileNode fileNode : fileNodes) {
fileNode.writeToDisk(gitDirectory); fileNode.writeToDisk(gitDirectory);
} }

View file

@ -41,6 +41,17 @@ public class WLFileStore {
} }
} }
public static void deleteInDirectoryApartFrom(File directory, String apartFrom) {
for (File file : directory.listFiles()) {
if (!file.getName().equals(apartFrom)) {
if (file.isDirectory()) {
deleteInDirectory(file);
}
file.delete();
}
}
}
public List<WritableRepositoryContents> updateForProject(WLProject project) throws FailedConnectionException, public List<WritableRepositoryContents> updateForProject(WLProject project) throws FailedConnectionException,
InvalidProjectException { InvalidProjectException {
SortedSet<Snapshot> snapshots = project.fetchNewSnapshots(); SortedSet<Snapshot> snapshots = project.fetchNewSnapshots();