You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ti...@apache.org on 2012/05/18 00:37:08 UTC

[12/19] js commit: writing to file works - yay

writing to file works - yay


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/487f5ee7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/487f5ee7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/487f5ee7

Branch: refs/heads/playbookFile
Commit: 487f5ee7c066124d15606c7eca5df3a42838d24b
Parents: 824cc9a
Author: Tim Kim <ti...@adobe.com>
Authored: Wed May 9 14:23:27 2012 -0700
Committer: Tim Kim <ti...@adobe.com>
Committed: Wed May 9 14:23:27 2012 -0700

----------------------------------------------------------------------
 lib/playbook/plugin/playbook/FileWriter.js |   23 ++++++++++++++++++-----
 1 files changed, 18 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/487f5ee7/lib/playbook/plugin/playbook/FileWriter.js
----------------------------------------------------------------------
diff --git a/lib/playbook/plugin/playbook/FileWriter.js b/lib/playbook/plugin/playbook/FileWriter.js
index f7f2186..91ef97f 100644
--- a/lib/playbook/plugin/playbook/FileWriter.js
+++ b/lib/playbook/plugin/playbook/FileWriter.js
@@ -89,22 +89,35 @@ FileWriter.prototype.write = function(text) {
     // and save again - lame
     // also have to investigate how bb blobs work in order to set proper seek positions :S
     console.log('writing to file');
+    
+    if (typeof me.onwrite === "function") {
+    	me.onwrite(new ProgressEvent("write", {"target":me}));
+    }
+    
     var textBlob = blackberry.utils.stringToBlob(text);
     if(blackberry.io.file.exists(this.fileName)){
         // for now just overwrite
         var oldTextBlob = '';
+        
         var getFileContents = function(path,blob){
+
             if(blob){
                 oldTextBlob = blackberry.utils.blobToString(blob);
             }
+
             // seek position stuff here
             var newTextBlob = text;
-            console.log('old text: ' + oldTextBlob);
-            console.log('new text: ' + newTextBlob);
-            blackberry.io.file.saveFile(this.fileName+'temp', blackberry.utils.stringToBlob(newTextBlob));
-            blackberry.io.file.deleteFile(this.fileName);
-            blackberry.io.file.rename(this.fileName+'temp', this.fileName);
+            var tempFile = me.fileName+'temp';
+            if(blackberry.io.file.exists(tempFile)){
+                blackberry.io.file.deleteFile(tempFile);
+            }
+			
+			// crete a temp file, delete file we are 'overwriting', then rename temp file
+            blackberry.io.file.saveFile(tempFile, blackberry.utils.stringToBlob(newTextBlob));
+            blackberry.io.file.deleteFile(me.fileName);
+            blackberry.io.file.rename(tempFile, me.fileName.split('/').pop());
         }
+
         // setting asynch to off - worry about making this all callbacks later
         blackberry.io.file.readFile(this.fileName, getFileContents, false);