From 3bbef6f06660583176488c9d7a0f38afce63b792 Mon Sep 17 00:00:00 2001 From: Winston Li Date: Mon, 17 Nov 2014 12:47:59 +0000 Subject: [PATCH] Now deleting all files before writing snapshot to disk. --- .../writelatex/filestore/GitDirectoryContents.java | 2 ++ .../writelatex/filestore/store/WLFileStore.java | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/GitDirectoryContents.java b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/GitDirectoryContents.java index 4fd381c68d..ce2b93d9f0 100644 --- a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/GitDirectoryContents.java +++ b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/GitDirectoryContents.java @@ -3,6 +3,7 @@ package uk.ac.ic.wlgitbridge.writelatex.filestore; import uk.ac.ic.wlgitbridge.bridge.WritableRepositoryContents; 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.store.WLFileStore; import uk.ac.ic.wlgitbridge.writelatex.model.Snapshot; import java.io.File; @@ -30,6 +31,7 @@ public class GitDirectoryContents implements WritableRepositoryContents { @Override public void write() throws IOException, FailedConnectionException { + WLFileStore.deleteInDirectoryApartFrom(gitDirectory, ".git"); for (FileNode fileNode : fileNodes) { fileNode.writeToDisk(gitDirectory); } diff --git a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/store/WLFileStore.java b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/store/WLFileStore.java index fceaa4ef16..ac6f2c43f8 100644 --- a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/store/WLFileStore.java +++ b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/store/WLFileStore.java @@ -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 updateForProject(WLProject project) throws FailedConnectionException, InvalidProjectException { SortedSet snapshots = project.fetchNewSnapshots();