incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tim...@apache.org
Subject [12/19] js commit: writing to file works - yay
Date Thu, 17 May 2012 22:37:08 GMT
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 <timk@adobe.com>
Authored: Wed May 9 14:23:27 2012 -0700
Committer: Tim Kim <timk@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);
 


Mime
View raw message