Skip to content

Commit

Permalink
Changed a bit of how FileUtils worked
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Schmidt committed Mar 31, 2012
1 parent fadd083 commit 92581a4
Showing 1 changed file with 28 additions and 34 deletions.
62 changes: 28 additions & 34 deletions hub/FileUtils.js
Expand Up @@ -3,42 +3,36 @@
var path = require ("path");

var FileUtils = {
home: (function () {
var cache = null;

return function () {
if (cache) return cache;

var home = process.env.HOME;

if (process.platorm === "win32") {
// Only believe $HOME if it exists
if (home) {
if (!path.existsSync (home)) {
home = null;
}
}

// In case HOME is Unix-style (it happens), convert it to
// Windows style.
if (home) {
home = home.replace (/\//g, "\\");
}

if (!home) {
// USERPROFILE is probably the closest equivalent to $HOME?
home = process.env.USERPROFILE;
home: function() {
var home = process.env.HOME;

if (process.platform === 'win32') {
// Only believe $HOME if it exists
if (home) {
if (!path.existsSync(home)) {
home = null;
}
}

// I don't think we can use the getpwid function in Node.js very easily
// If home still isn't set, we use the current dir I guess

if (!home) home = ".";

return cache = home;
};
}) ()
// In case HOME is Unix-style (it happens), convert it to
// Windows style.
if (home) {
home = home.replace(/\//g, '\\');
}

if (!home) {
// USERPROFILE is probably the closest equivalent to $HOME?
home = process.env.USERPROFILE;
}
}

// I don't think we can use the getpwid function in Node.js very easily
// If home still isn't set, we use the current dir I guess
if (!home) {
home = '.';
}

return home;
}
};

module.exports = FileUtils;

0 comments on commit 92581a4

Please sign in to comment.