incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tim...@apache.org
Subject [40/48] js commit: writing to file works - yay
Date Thu, 07 Jun 2012 20:40:44 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/ecf5cec5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/ecf5cec5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/ecf5cec5

Branch: refs/heads/master
Commit: ecf5cec5663a0dc62aa87d26c2cf581aa0a7e497
Parents: 23ccd0b
Author: Tim Kim <timk@adobe.com>
Authored: Wed May 9 14:23:27 2012 -0700
Committer: Tim Kim <tim.kim@nitobi.com>
Committed: Thu Jun 7 13:40:22 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/ecf5cec5/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