Bug 648364 - Replace custom helpers with FileUtils.jsm. r=rnewman

This commit is contained in:
Philipp von Weitershausen 2011-05-19 18:08:51 -07:00
Родитель a3ec746039
Коммит dd0e93f304
3 изменённых файлов: 13 добавлений и 40 удалений

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

@ -60,6 +60,7 @@ const KEYS_WBO = "keys";
const LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S";
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");
Cu.import("resource://services-sync/record.js");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/engines.js");
@ -490,13 +491,8 @@ WeaveSvc.prototype = {
let enabled = Svc.Prefs.get("log.appender.debugLog.enabled", false);
if (enabled) {
let verbose = Services.dirsvc.get("ProfD", Ci.nsIFile);
verbose.QueryInterface(Ci.nsILocalFile);
verbose.append("weave");
verbose.append("logs");
verbose.append("verbose-log.txt");
if (!verbose.exists())
verbose.create(verbose.NORMAL_FILE_TYPE, PERMS_FILE);
let verbose = FileUtils.getFile(
"ProfD", ["weave", "logs", "verbose-log.txt"], true);
if (Svc.Prefs.get("log.appender.debugLog.rotate", true)) {
let maxSize = Svc.Prefs.get("log.appender.debugLog.maxSize");

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

@ -52,6 +52,7 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/PlacesUtils.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");
// Constants for makeSyncCallback, waitForSyncCallback
const CB_READY = {};
@ -296,32 +297,12 @@ let Utils = {
window.addEventListener("unload", function() windows[url] = null, false);
},
// Returns a nsILocalFile representing a file relative to the
// current user's profile directory. If the argument is a string,
// it should be a string with unix-style slashes for directory names
// (these slashes are automatically converted to platform-specific
// path separators).
//
// Alternatively, if the argument is an object, it should contain
// the following attributes:
//
// path: the path to the file, relative to the current user's
// profile dir.
//
// autoCreate: whether or not the file should be created if it
// doesn't already exist.
getProfileFile: function getProfileFile(arg) {
if (typeof arg == "string")
arg = {path: arg};
let pathParts = arg.path.split("/");
let file = Services.dirsvc.get("ProfD", Ci.nsIFile);
file.QueryInterface(Ci.nsILocalFile);
for (let i = 0; i < pathParts.length; i++)
file.append(pathParts[i]);
if (arg.autoCreate && !file.exists())
file.create(file.NORMAL_FILE_TYPE, PERMS_FILE);
return file;
// Returns a nsILocalFile representing a file relative to the current
// user's profile directory. The argument should be a string with
// unix-style slashes for directory names (these slashes are automatically
// converted to platform-specific path separators).
getProfileFile: function getProfileFile(path) {
return FileUtils.getFile("ProfD", path.split("/"), true);
},
/**
@ -1031,14 +1012,11 @@ let Utils = {
if (that._log)
that._log.trace("Saving json to disk: " + filePath);
let file = Utils.getProfileFile({ autoCreate: true, path: filePath });
let file = Utils.getProfileFile(filePath);
let json = typeof obj == "function" ? obj.call(that) : obj;
let out = JSON.stringify(json);
let fos = Cc["@mozilla.org/network/safe-file-output-stream;1"]
.createInstance(Ci.nsIFileOutputStream);
fos.init(file, MODE_WRONLY | MODE_CREATE | MODE_TRUNCATE, PERMS_FILE,
fos.DEFER_OPEN);
let fos = FileUtils.openSafeFileOutputStream(file);
let is = this._utf8Converter.convertToInputStream(out);
NetUtil.asyncCopy(is, fos, function (result) {
if (typeof callback == "function") {

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

@ -68,8 +68,7 @@ add_test(function test_load_logging() {
_("Verify that reads and read errors are logged.");
// Write a file with some invalid JSON
let file = Utils.getProfileFile({ autoCreate: true,
path: "weave/log.json" });
let file = Utils.getProfileFile("weave/log.json");
let fos = Cc["@mozilla.org/network/file-output-stream;1"]
.createInstance(Ci.nsIFileOutputStream);
fos.init(file, MODE_WRONLY | MODE_CREATE | MODE_TRUNCATE, PERMS_FILE,