Browse Source

Made changed be calculated dynamically.

Winston Li 12 years ago
parent
commit
e52ef90e13

+ 11 - 2
services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/node/AttachmentNode.java

@@ -3,10 +3,10 @@ package uk.ac.ic.wlgitbridge.writelatex.filestore.node;
 import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
 import uk.ac.ic.wlgitbridge.writelatex.api.request.getforversion.SnapshotAttachment;
 import uk.ac.ic.wlgitbridge.writelatex.filestore.blob.AttachmentBlob;
-import uk.ac.ic.wlgitbridge.writelatex.filestore.blob.ByteBlob;
-import uk.ac.ic.wlgitbridge.writelatex.filestore.store.FileIndexStore;
 import uk.ac.ic.wlgitbridge.writelatex.filestore.blob.Blob;
+import uk.ac.ic.wlgitbridge.writelatex.filestore.blob.ByteBlob;
 import uk.ac.ic.wlgitbridge.writelatex.filestore.blob.ExternalBlob;
+import uk.ac.ic.wlgitbridge.writelatex.filestore.store.FileIndexStore;
 import uk.ac.ic.wlgitbridge.writelatex.model.db.PersistentStoreAPI;
 
 import java.util.Map;
@@ -43,6 +43,15 @@ public class AttachmentNode extends FileNode {
         this.blob = new ByteBlob(blob);
     }
 
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof AttachmentNode)) {
+            return false;
+        }
+        AttachmentNode that = (AttachmentNode) obj;
+        return super.equals(obj) && url.equals(that.url);
+    }
+
     @Override
     public void indexWith(FileNodeIndexer fileNodeIndexer) {
         fileNodeIndexer.index(this);

+ 6 - 5
services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/filestore/node/FileNode.java

@@ -17,16 +17,16 @@ import java.util.Map;
 public abstract class FileNode implements PersistentStoreUpdater<String> {
 
     private final String filePath;
-    private final boolean changed;
+    private FileNode previous;
+    private boolean changed;
 
     public FileNode(RawFile file, Map<String, FileNode> context) {
         this(file.getPath(), context);
     }
 
     public FileNode(String filePath, Map<String, FileNode> context) {
-        FileNode currentFileNode = context.get(filePath);
+        previous = context.get(filePath);
         this.filePath = filePath;
-        changed = currentFileNode == null || !equals(currentFileNode);
     }
 
     protected FileNode(String filePath, boolean changed) {
@@ -36,6 +36,7 @@ public abstract class FileNode implements PersistentStoreUpdater<String> {
 
     protected FileNode() {
         filePath = "";
+        previous = null;
         changed = false;
     }
 
@@ -57,7 +58,7 @@ public abstract class FileNode implements PersistentStoreUpdater<String> {
     }
 
     public boolean isChanged() {
-        return changed;
+        return changed || previous == null || !equals(previous);
     }
 
     public abstract void indexWith(FileNodeIndexer indexer);
@@ -70,7 +71,7 @@ public abstract class FileNode implements PersistentStoreUpdater<String> {
 
     @Override
     public String toString() {
-        return String.valueOf(changed);
+        return filePath;
     }
 
 }