1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-04 05:25:45 +01:00

use 'CurWorkD' for the default value of the internal CWD

This commit is contained in:
Doug Kearns
2008-10-02 10:53:34 +00:00
parent 37e5b59db5
commit ba94b70bf2

View File

@@ -27,6 +27,7 @@ the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL. the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/ }}} ***** END LICENSE BLOCK *****/
// TODO: why are we passing around strings rather than file objects?
liberator.IO = function () //{{{ liberator.IO = function () //{{{
{ {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -38,8 +39,13 @@ liberator.IO = function () //{{{
var environmentService = Components.classes["@mozilla.org/process/environment;1"] var environmentService = Components.classes["@mozilla.org/process/environment;1"]
.getService(Components.interfaces.nsIEnvironment); .getService(Components.interfaces.nsIEnvironment);
var directoryService = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
var processDir = directoryService.get("CurWorkD", Components.interfaces.nsIFile);
var cwd = processDir.path;
var oldcwd = null;
var cwd = null, oldcwd = null;
var lastRunCommand = ""; // updated whenever the users runs a command with :! var lastRunCommand = ""; // updated whenever the users runs a command with :!
var scriptNames = []; var scriptNames = [];
@@ -421,40 +427,23 @@ liberator.IO = function () //{{{
return path; return path;
}, },
// TODO: there seems to be no way, short of a new component, to change
// Firefox's CWD - see // https://bugzilla.mozilla.org/show_bug.cgi?id=280953
getCurrentDirectory: function () getCurrentDirectory: function ()
{ {
var file = Components.classes["@mozilla.org/file/local;1"] let dir = ioManager.getFile(cwd);
.createInstance(Components.interfaces.nsILocalFile);
// FIXME: why aren't we using the "CurWorkD" special directory -- djk // NOTE: the directory could have been deleted underneath us so
var dirs = [cwd, "$PWD", "~"]; // fallback to Firefox's CWD
for (let i = 0; i < dirs.length; i++) if (dir.exists() && dir.isDirectory())
{ return dir.path;
if (!dirs[i]) else
continue; return processDir.path;
var fullname = ioManager.expandPath(dirs[i]);
try
{
file.initWithPath(fullname);
}
catch (e)
{
continue;
}
if (file.exists() && file.isDirectory())
return fullname;
}
// just make sure we return something which always is a directory
return WINDOWS ? "C:\\" : "/"; // XXX
}, },
setCurrentDirectory: function (newdir) setCurrentDirectory: function (newdir)
{ {
if (!newdir) newdir = newdir || "~";
newdir = "~";
if (newdir == "-") if (newdir == "-")
{ {
@@ -462,14 +451,15 @@ liberator.IO = function () //{{{
} }
else else
{ {
newdir = ioManager.expandPath(newdir); let dir = ioManager.getFile(newdir);
var file = ioManager.getFile(newdir);
if (!file.exists() || !file.isDirectory()) if (!dir.exists() || !dir.isDirectory())
{ {
liberator.echoerr("E344: Can't find directory \"" + newdir + "\" in path"); liberator.echoerr("E344: Can't find directory \"" + dir.path + "\" in path");
return null; return null;
} }
[cwd, oldcwd] = [newdir, this.getCurrentDirectory()];
[cwd, oldcwd] = [dir.path, this.getCurrentDirectory()];
} }
return ioManager.getCurrentDirectory(); return ioManager.getCurrentDirectory();
@@ -530,7 +520,6 @@ liberator.IO = function () //{{{
// TODO: make secure // TODO: make secure
// returns a nsILocalFile or null if it could not be created // returns a nsILocalFile or null if it could not be created
// FIXME: is there a reason the "TmpD" special directory isn't being used? -- djk
createTempFile: function () createTempFile: function ()
{ {
let tmpName = EXTENSION_NAME + ".tmp"; let tmpName = EXTENSION_NAME + ".tmp";
@@ -550,9 +539,7 @@ liberator.IO = function () //{{{
break; break;
} }
let file = Components.classes["@mozilla.org/file/directory_service;1"] let file = directoryService.get("TmpD", Components.interfaces.nsIFile);
.getService(Components.interfaces.nsIProperties)
.get("TmpD", Components.interfaces.nsIFile);
file.append(tmpName); file.append(tmpName);
file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0600); file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0600);