| author | Piotr Janik | 2011-07-05 06:59:05 (EDT) |
|---|---|---|
| committer | Szymon Brandys | 2011-07-05 06:59:05 (EDT) |
| commit | f736a3053fe9694d8b2e45c6c8f3620a0460dec4 (patch) (side-by-side diff) | |
| tree | d001b7bdf65e46e397a8cddf7a6d25f76d8ccee2 | |
| parent | e57e6b15ce03ea003370757f61eb3eca9813bc72 (diff) | |
| download | org.eclipse.orion.client-f736a3053fe9694d8b2e45c6c8f3620a0460dec4.zip org.eclipse.orion.client-f736a3053fe9694d8b2e45c6c8f3620a0460dec4.tar.gz org.eclipse.orion.client-f736a3053fe9694d8b2e45c6c8f3620a0460dec4.tar.bz2 | |
bug 350410 - File content overridden when saved from multiple editorsv20110705-1140v20110705-1110v20110705-1045
https://bugs.eclipse.org/bugs/show_bug.cgi?id=350410
3 files changed, 56 insertions, 13 deletions
diff --git a/bundles/org.eclipse.orion.client.core/web/orion/editorCommands.js b/bundles/org.eclipse.orion.client.core/web/orion/editorCommands.js index 4c48257..d25f32f 100644 --- a/bundles/org.eclipse.orion.client.core/web/orion/editorCommands.js +++ b/bundles/org.eclipse.orion.client.core/web/orion/editorCommands.js @@ -45,12 +45,39 @@ exports.EditorCommandFactory = (function() { editor.getTextView().setKeyBinding(new mKeyBinding.KeyBinding('s', true), "Save"); editor.getTextView().setAction("Save", dojo.hitch(this, function () { var contents = editor.getTextView().getText(); - this.fileClient.write(this.inputManager.getInput(), contents).then(dojo.hitch(this, function() { - editor.onInputChange(this.inputManager.getInput(), null, contents, true); - if(this.inputManager.afterSave){ - this.inputManager.afterSave(); - } - })); + var etag = this.inputManager.getFileMetadata().ETag; + var args = { "ETag" : etag }; + this.fileClient.write(this.inputManager.getInput(), contents, args).then( + dojo.hitch(this, function(result) { + this.inputManager.getFileMetadata().ETag = result.ETag; + editor.onInputChange(this.inputManager.getInput(), null, contents, true); + if(this.inputManager.afterSave){ + this.inputManager.afterSave(); + } + }), + dojo.hitch(this, function(error) { + // expected error - HTTP 412 Precondition Failed + // occurs when file is out of sync with the server + if (error.status == 412) { + var forceSave = confirm("Resource is out of sync with the server. Do you want to save it anyway?"); + if (forceSave) { + // repeat save operation, but without ETag + this.fileClient.write(this.inputManager.getInput(), contents).then( + dojo.hitch(this, function(result) { + this.inputManager.getFileMetadata().ETag = result.ETag; + editor.onInputChange(this.inputManager.getInput(), null, contents, true); + if(this.inputManager.afterSave){ + this.inputManager.afterSave(); + } + })); + } + } + // unknown error + else { + error.log = true; + } + }) + ); return true; })); var saveCommand = new mCommands.Command({ diff --git a/bundles/org.eclipse.orion.client.core/web/orion/fileClient.js b/bundles/org.eclipse.orion.client.core/web/orion/fileClient.js index 10a4b18..8c5eae5 100644 --- a/bundles/org.eclipse.orion.client.core/web/orion/fileClient.js +++ b/bundles/org.eclipse.orion.client.core/web/orion/fileClient.js @@ -145,9 +145,10 @@ define(["dojo", "orion/auth"], function(dojo, mAuth){ * * @param {String} location The location of the file to set contents for * @param {String|Object} contents The content string, or metadata object to write - * @return A deferred for chaining events after the write completes + * @param {String|Object} args Additional arguments used during write operation (i.e. ETag) + * @return A deferred for chaining events after the write completes with new metadata object */ - write: function(location, contents) { + write: function(location, contents, args) { return this._doServiceCall("write", arguments); }, diff --git a/bundles/org.eclipse.orion.client.core/web/plugins/filePlugin/fileImpl.js b/bundles/org.eclipse.orion.client.core/web/plugins/filePlugin/fileImpl.js index 6c699e2..f0edd83 100644 --- a/bundles/org.eclipse.orion.client.core/web/plugins/filePlugin/fileImpl.js +++ b/bundles/org.eclipse.orion.client.core/web/plugins/filePlugin/fileImpl.js @@ -310,19 +310,34 @@ eclipse.FileServiceImpl= (function() { * * @param {String} location The location of the file to set contents for * @param {String|Object} contents The content string, or metadata object to write - * @return A deferred for chaining events after the write completes + * @param {String|Object} args Additional arguments used during write operation (i.e. ETag) + * @return A deferred for chaining events after the write completes with new metadata object */ - write: function(location, contents) { + write: function(location, contents, args) { + var headerData = { + "Orion-Version": "1" + }; + if (args && args.ETag) { + headerData["If-Match"] = args.ETag; + } var xhrArgs = { url: location, timeout: 5000, - headers: { "Orion-Version": "1" }, - putData: contents + headers: headerData, + putData: contents, + handleAs: "json", + load: function(jsonData, ioArgs) { + return jsonData; + }, + error: function(error) { + error.log = false; + return error; + }, + failOk: true }; //some different header for putting metadata if (typeof contents !== "string") { xhrArgs.url = location + "?parts=meta"; - xhrArgs.handleAs = "json"; } return dojo.xhrPut(xhrArgs); }, |

