Răsfoiți Sursa

Delete project atts directory after push.

Winston Li 11 ani în urmă
părinte
comite
ec0c70c622

+ 9 - 2
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<ServletFile> files;
     private final List<String> 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();

+ 5 - 1
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);
         }
     }