Search code examples
javascriptfirefox-addonxpcom

Waiting for file copy to finish in Firefox extension


I have code to copy a file to a new location, then open the file at this new location. As far as I can tell, there is a problem that the code may try to open the file before the copy has been completed.

This problem is specific to a Firefox extension which is copying an sqlite database from a default location to a new location specified by the user. If the sqlite file doesn't exist in the new location, then the call to openDatabase will create a new, blank database.

// some pseudocode
var old_path // is an nsILocalFile instance
var new_path // is an nsILocalFile instance

// copy file
old_path.copyTo(new_path)

// open sqlite database
var ss = Components.classes["@mozilla.org/storage/service;1"]
         .getService(Components.interfaces.mozIStorageService);
var db = ss.openDatabase(new_path)

How can I wait for the copy to be completed? (Events, event listeners, observers...?)


Solution

  • Neil's comment to my question prompted me to check my code and I think I have found a bug which caused the sqlite file to be overwritten by mistake.

    Closing question.