I'm trying to copy a sqlite database from the data folder in my extension directory, to the profile folder, in order to use it.
So for now, I'm trying with that:
const {Cc, Ci, Cu} = require("chrome"); const {NetUtils} = Cu.import("resource://gre/modules/NetUtil.jsm"); const data = require('sdk/self').data; Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/FileUtils.jsm"); var file = Cc["@mozilla.org/file/directory_service;1"]. getService(Ci.nsIProperties). get("TmpD", Ci.nsIFile); file.append("searchEngines.sqlite"); file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); // Then, we need an output stream to our output file. var ostream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream); ostream.init(file, -1, -1, 0); // Finally, we need an input stream to take data from. var iStreamData = NetUtil.ioService.newChannel(data.url("searchEngines.sqlite"), null, null).open(); let istream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci.nsIStringInputStream); istream.setData(iStreamData, iStreamData.length); NetUtil.asyncCopy(istream, ostream, function(aResult) { console.log(aResult); // return 0 }) console.log(FileUtils.getFile("ProfD", ["searchEngines.sqlite"]).exists()); // return false let dbConn = Services.storage.openDatabase(file); The file seems to exist since the console.log(file.exists()) return FALSE and is not populated (the console.log(aResult) return 0).
Where is my mistake, and is there a better way to do that?
filetwice. I assume this is an error, and only the latterTmpDinstance is to be considered?file.exists()return true. It's an error after several copy/paste. Should I edit my question?