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 9409c2fd1b..8f2252f322 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 @@ -23,6 +23,7 @@ public class CandidateSnapshot { private final int currentVersion; private final List files; private final List deleted; + private File attsDirectory; public CandidateSnapshot(String projectName, int currentVersion, RawDirectory directoryContents, RawDirectory oldDirectoryContents) { this.projectName = projectName; @@ -56,14 +57,20 @@ public class CandidateSnapshot { } public void writeServletFiles(File rootGitDirectory) throws IOException { - File directory = new File(rootGitDirectory, ".wlgb/atts/" + projectName); + attsDirectory = new File(rootGitDirectory, ".wlgb/atts/" + projectName); for (ServletFile file : files) { if (file.isChanged()) { - file.writeToDisk(directory); + file.writeToDisk(attsDirectory); } } } + public void deleteServletFiles() throws IOException { + if (attsDirectory != null) { + Util.deleteInDirectory(attsDirectory); + } + } + public JsonElement getJsonRepresentation(String postbackKey) { String projectURL = Util.getPostbackURL() + projectName; JsonObject jsonObject = new JsonObject(); diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/WriteLatexAPI.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/WriteLatexAPI.java index 1bccf4bfb5..cad8b757a8 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/WriteLatexAPI.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/WriteLatexAPI.java @@ -71,10 +71,11 @@ public class WriteLatexAPI implements WriteLatexDataSource { @Override public void putDirectoryContentsToProjectWithName(String projectName, RawDirectory directoryContents, RawDirectory oldDirectoryContents, String hostname) throws SnapshotPostException, IOException { mainProjectLock.lockForProject(projectName); + CandidateSnapshot candidate = null; try { Util.sout("Pushing project: " + projectName); String postbackKey = postbackManager.makeKeyForProject(projectName); - CandidateSnapshot candidate = dataModel.createCandidateSnapshotFromProjectWithContents(projectName, directoryContents, oldDirectoryContents); + candidate = dataModel.createCandidateSnapshotFromProjectWithContents(projectName, directoryContents, oldDirectoryContents); SnapshotPushRequest snapshotPushRequest = new SnapshotPushRequest(candidate, postbackKey); snapshotPushRequest.request(); SnapshotPushRequestResult result = snapshotPushRequest.getResult(); @@ -91,6 +92,9 @@ public class WriteLatexAPI implements WriteLatexDataSource { } catch (IOException e) { throw e; } finally { + if (candidate != null) { + candidate.deleteServletFiles(); + } mainProjectLock.unlockForProject(projectName); } }