mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 16:25:38 +00:00
Bug 1339105 Part 2: Fix registerFakePath in head_migration.js to work when the key has already been accessed. r=mak
This also fixes the cleanup to fully remove the fake path and put back original if it existed.
This commit is contained in:
parent
edf3a239b1
commit
ad828b90f2
@ -49,21 +49,25 @@ function promiseMigration(migrator, resourceType, aProfile = null) {
|
||||
* Replaces a directory service entry with a given nsIFile.
|
||||
*/
|
||||
function registerFakePath(key, file) {
|
||||
// Register our own provider for the Library directory.
|
||||
let provider = {
|
||||
getFile(prop, persistent) {
|
||||
persistent.value = true;
|
||||
if (prop == key) {
|
||||
return file;
|
||||
}
|
||||
throw Cr.NS_ERROR_FAILURE;
|
||||
},
|
||||
QueryInterface: XPCOMUtils.generateQI([ Ci.nsIDirectoryServiceProvider ])
|
||||
};
|
||||
Services.dirsvc.QueryInterface(Ci.nsIDirectoryService)
|
||||
.registerProvider(provider);
|
||||
let dirsvc = Services.dirsvc.QueryInterface(Ci.nsIProperties);
|
||||
let originalFile;
|
||||
try {
|
||||
// If a file is already provided save it and undefine, otherwise set will
|
||||
// throw for persistent entries (ones that are cached).
|
||||
originalFile = dirsvc.get(key, Ci.nsIFile);
|
||||
dirsvc.undefine(key);
|
||||
} catch (e) {
|
||||
// dirsvc.get will throw if nothing provides for the key and dirsvc.undefine
|
||||
// will throw if it's not a persistent entry, in either case we don't want
|
||||
// to set the original file in cleanup.
|
||||
originalFile = undefined;
|
||||
}
|
||||
|
||||
dirsvc.set(key, file);
|
||||
do_register_cleanup(() => {
|
||||
Services.dirsvc.QueryInterface(Ci.nsIDirectoryService)
|
||||
.unregisterProvider(provider);
|
||||
dirsvc.undefine(key);
|
||||
if (originalFile) {
|
||||
dirsvc.set(key, originalFile);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user