Bug 1772937 - Port osfile.jsm usage to IOUtils in toolkit/components/satchel/ r=adw

Differential Revision: https://phabricator.services.mozilla.com/D153703
This commit is contained in:
Barret Rennie 2022-08-09 17:40:45 +00:00
Родитель 95f5a70c44
Коммит 833113a4cf
2 изменённых файлов: 15 добавлений и 16 удалений

Просмотреть файл

@ -94,7 +94,6 @@ const { AppConstants } = ChromeUtils.import(
const lazy = {};
ChromeUtils.defineModuleGetter(lazy, "OS", "resource://gre/modules/osfile.jsm");
ChromeUtils.defineModuleGetter(
lazy,
"Sqlite",
@ -785,7 +784,7 @@ var DB = {
/** String representing where the FormHistory database is on the filesystem */
get path() {
return lazy.OS.Path.join(lazy.OS.Constants.Path.profileDir, DB_FILENAME);
return PathUtils.join(PathUtils.profileDir, DB_FILENAME);
},
/**
@ -980,12 +979,13 @@ var DB = {
await conn.close();
}
let backupFile = this.path + ".corrupt";
let { file, path: uniquePath } = await lazy.OS.File.openUnique(backupFile, {
humanReadable: true,
});
await file.close();
await lazy.OS.File.copy(this.path, uniquePath);
await lazy.OS.File.remove(this.path);
let uniquePath = await IOUtils.createUniqueFile(
PathUtils.parent(backupFile),
PathUtils.filename(backupFile),
0o600
);
await IOUtils.copy(this.path, uniquePath);
await IOUtils.remove(this.path);
log("Completed DB cleanup.");
},

Просмотреть файл

@ -18,7 +18,6 @@ var { XPCOMUtils } = ChromeUtils.importESModule(
XPCOMUtils.defineLazyModuleGetters(this, {
FormHistory: "resource://gre/modules/FormHistory.jsm",
FormHistoryTestUtils: "resource://testing-common/FormHistoryTestUtils.jsm",
OS: "resource://gre/modules/osfile.jsm",
Sqlite: "resource://gre/modules/Sqlite.jsm",
});
@ -205,21 +204,21 @@ async function copyToProfile(
aDestFilename,
{ overwriteExisting = false } = {}
) {
let curDir = await OS.File.getCurrentDirectory();
let srcPath = OS.Path.join(curDir, aFilename);
Assert.ok(await OS.File.exists(srcPath), "Database file found");
let curDir = Services.dirsvc.get("CurWorkD", Ci.nsIFile).path;
let srcPath = PathUtils.join(curDir, aFilename);
Assert.ok(await IOUtils.exists(srcPath), "Database file found");
// Ensure that our file doesn't exist already.
let destPath = OS.Path.join(OS.Constants.Path.profileDir, aDestFilename);
let exists = await OS.File.exists(destPath);
let destPath = PathUtils.join(PathUtils.profileDir, aDestFilename);
let exists = await IOUtils.exists(destPath);
if (exists) {
if (overwriteExisting) {
await OS.file.remove(destPath);
await IOUtils.remove(destPath);
} else {
throw new Error("The file should not exist");
}
}
await OS.File.copy(srcPath, destPath);
await IOUtils.copy(srcPath, destPath);
info(`Copied ${aFilename} to ${destPath}`);
return destPath;
}