Skip to content

Commit 5ea97ac

Browse files
committed
Correct new filesync with buffers
1 parent 7cb9d8d commit 5ea97ac

4 files changed

Lines changed: 25 additions & 4 deletions

File tree

client/models/file.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ define([
272272
"size": 0,
273273
"mtime": 0,
274274
"mime": "inode/directory",
275-
"href": "/vfs/"
275+
"href": "/vfs/",
276+
"exists": true
276277
};
277278
this.set(fileData);
278279
return Q(fileData);
@@ -285,6 +286,7 @@ define([
285286
return file.name == filename;
286287
});
287288
if (fileData != null) {
289+
fileData.exists = true;
288290
that.set(fileData);
289291
return Q(fileData);
290292
} else {

client/utils/filesync.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,17 @@ define([
220220
socket.on('message', function(data) {
221221
logging.log("socket receive packet ", data);
222222
self.ping = true;
223+
224+
// Calid data
223225
if (data.action == null || data.environment == null || self.envId != data.environment) {
224226
return;
225227
}
226228

229+
// Changement file
230+
if (data.path && (!self.file || data.path != self.file.path())) {
231+
self.trigger("file:path", data.path);
232+
}
233+
227234
switch (data.action) {
228235
case "cursor":
229236
if (data.from != user.get("userId")) {
@@ -291,7 +298,8 @@ define([
291298
options = _.defaults({}, options || {}, {
292299
sync: true,
293300
readonly: false,
294-
cache: true
301+
cache: true,
302+
autoload: true
295303
});
296304
options.readonly = this.sync ? options.readonly : true;
297305

@@ -308,6 +316,12 @@ define([
308316
if (this.file != null) {
309317
this.file.on("set", _.partial(this.setFile, this.file, options), this);
310318
this.trigger("mode", this.file.mode());
319+
if (options.autoload) {
320+
this.on("file:path", function(path) {
321+
console.log("update file with path ", path);
322+
this.file.getByPath(path);
323+
}, this);
324+
}
311325

312326
this.updateEnv(this.file.syncEnvId(), options);
313327
}

core/cb.files.sync/environment.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,14 @@ Environment.prototype.sync = function(user, payload) {
190190
Environment.prototype.save = function(user, payload) {
191191
var that = this;
192192

193+
if (payload.path) {
194+
this.doc.setPath(payload.path);
195+
}
196+
193197
// Synchronize content
194198
this.doc.save().then(function() {
195199
that.modifiedState(false);
200+
that.syncAll();
196201
});
197202
};
198203

@@ -208,7 +213,8 @@ Environment.prototype.load = function(user, payload) {
208213
throw new Error("User was not allowed to open file");
209214
}
210215

211-
return that.doc.setPath(payload.path)
216+
that.doc.setPath(payload.path);
217+
return that.doc.load();
212218
}).then(function() {
213219
that.syncAll();
214220
});

core/cb.files.sync/models/document.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ Document.prototype.save = function() {
5858

5959
Document.prototype.setPath = function(path) {
6060
this.path = path;
61-
return this.load();
6261
};
6362

6463
Document.prototype.load = function() {

0 commit comments

Comments
 (0)