From 0e84fc2139daf78dab7cf98e92dd394a1ab8ff75 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Mon, 17 Feb 2014 13:25:42 -0800 Subject: [PATCH] Use async IO to dump data from storage module. --- common/modules/storage.jsm | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/common/modules/storage.jsm b/common/modules/storage.jsm index 2c28b3f4..21815418 100644 --- a/common/modules/storage.jsm +++ b/common/modules/storage.jsm @@ -13,6 +13,8 @@ lazyRequire("config", ["config"]); lazyRequire("io", ["IO"]); lazyRequire("overlay", ["overlay"]); +lazyRequire("resource://gre/modules/osfile.jsm", ["OS"]); + var win32 = /^win(32|nt)$/i.test(services.runtime.OS); var myObject = JSON.parse("{}").constructor; @@ -52,7 +54,8 @@ var StoreBase = Class("StoreBase", { delete: function delete_() { delete storage.keys[this.name]; delete storage[this.name]; - storage.infoPath.child(this.name).remove(false); + return OS.File.remove( + storage.infoPath.child(this.name).path); }, save: function () { (self.storage || storage)._saveData(this); }, @@ -215,8 +218,12 @@ var Storage = Module("Storage", { _saveData: function saveData(obj) { if (obj.privateData && storage.privateMode) return; - if (obj.store && storage.infoPath) - storage.infoPath.child(obj.name).write(obj.serial); + if (obj.store && storage.infoPath) { + var { path } = storage.infoPath.child(obj.name); + return OS.File.writeAtomic( + path, obj.serial, + { tmpPath: path + ".part" }); + } }, storeForSession: function storeForSession(key, val) { @@ -238,7 +245,8 @@ var Storage = Module("Storage", { this[key].timer.flush(); delete this[key]; delete this.keys[key]; - this.infoPath.child(key).remove(false); + return OS.File.remove( + this.infoPath.child(key).path); } },