Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More path stuff for Windows.

  • Loading branch information...
commit f168277ac7917741b86c0a673377c6107f1b139a 1 parent c411ec5
Matthew Eernisse mde authored
Showing with 33 additions and 25 deletions.
  1. +15 −17 lib/app.js
  2. +8 −4 lib/base_config.js
  3. +10 −4 lib/cluster/master.js
32 lib/app.js
View
@@ -20,7 +20,7 @@ var fs = require('fs')
, url = require('url')
, querystring = require('querystring')
, path = require('path')
- , dir = process.cwd()
+ , cwd = process.cwd()
, errors = require('./errors')
, response = require('./response')
, model = require('./model')
@@ -49,7 +49,7 @@ var App = function () {
var JSPAT = /\.js$/;
var _getDirList = function (dirname) {
- var dirList = fs.readdirSync(dir + dirname)
+ var dirList = fs.readdirSync(dirname)
, fileName
, filePath
, ctorName
@@ -64,7 +64,7 @@ var App = function () {
// Convert underscores to camelCase with
// initial cap, e.g., 'NeilPearts'
ctorName = geddy.string.camelize(fileName, true);
- filePath = dir + dirname + '/' + fileName;
+ filePath = path.join(cwd, dirname, fileName);
ret.push({
ctorName: ctorName
, filePath: filePath
@@ -77,15 +77,15 @@ var App = function () {
// Load models
// ==================
, _registerModels = function (next) {
- var dirname = '/app/models'
+ var modelDir = 'app/models'
, dirList
, item;
// May be running entirely model-less
- if (!path.existsSync(dir + dirname)) {
+ if (!path.existsSync(path.join(cwd + modelDir))) {
Paul Golmann
pjeweb added a note

This breaks on linux (means no modules will be loaded at all)! Missing one slash betweeen cwd and modelDir!
cwd has no trailing slash at least on Linux version 2.6.32-30

Matthew Eernisse Owner
mde added a note

Yes, should have changed the plus to a comma. Just pushed a fix to NPM (v0.3.15). Nice catch. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
next();
}
else {
- dirList = _getDirList(dirname)
+ dirList = _getDirList(modelDir)
// Dynamically create controller
// constructors from files in app/models
for (var i = 0; i < dirList.length; i++) {
@@ -99,8 +99,8 @@ var App = function () {
// Load controller ctors
// ==================
, _registerConstructors = function (next) {
- var dirname = '/app/controllers'
- , dirList = _getDirList(dirname)
+ var controllerDir = 'app/controllers'
+ , dirList = _getDirList(controllerDir)
, item
, ctors = {}
, ctor;
@@ -119,7 +119,7 @@ var App = function () {
// Load the router
// ==================
, _loadRouter = function (next) {
- router = require(dir + '/config/router');
+ router = require(path.join(cwd, '/config/router'));
router = router.router || router;
this.router = router;
next();
@@ -156,11 +156,10 @@ var App = function () {
// Register template-paths
// ==================
, _registerTemplatePaths = function (next) {
- var self = this
- , viewsPath = dir + '/app/views';
+ var viewsPath = path.normalize('app/views');
// May be running entirely viewless
if (!path.existsSync(viewsPath)) {
- self.templateRegistry = {};
+ this.templateRegistry = {};
next();
}
else {
@@ -172,12 +171,10 @@ var App = function () {
for (var i = 0; i < files.length; i++) {
file = files[i];
if (pat.test(file)) {
- file = file.replace(dir + '/', '');
- file = path.normalize(file);
templates[file] = true;
}
}
- self.templateRegistry = templates;
+ this.templateRegistry = templates;
next();
}
}
@@ -185,8 +182,9 @@ var App = function () {
// Run code in the app's config/init.js
// ==================
, _runAppLocalInit = function (next) {
- if (path.existsSync(dir + '/config/init.js')) {
- require(dir + '/config/init');
+ var initPath = path.join(cwd, 'config/init.js');
+ if (path.existsSync(initPath)) {
+ require(initPath);
}
next();
};
12 lib/base_config.js
View
@@ -1,4 +1,8 @@
- var config = {
+ var path = require('path')
+ , config
+ , cwd = process.cwd();
+
+config = {
// Default to prod
environment: 'development'
// Number of worker-processes to spawn
@@ -14,7 +18,7 @@
// How long to wait for in-flight requests before rotating
, rotationTimeout: 5 * 60 * 1000
// Default logfile location
-, logDir: process.cwd() + '/log'
+, logDir: path.normalize(cwd + '/log')
// How long to wait for in-flight requests before killing
, gracefulShutdownTimeout: 30000
// Number of milliseconds between heartbeat calls from
@@ -24,7 +28,7 @@
// before assuming a worker is hung, and needs to be killed
, heartbeatWindow: 20000
// Place to look for static content to serve in dev-mode
-, staticFilePath: process.cwd() + '/public'
+, staticFilePath: path.normalize(cwd + '/public')
// Default session-settings -- setting to null will mean no sessions
, sessions: {
store: 'memory',
@@ -38,7 +42,7 @@
// Where to look for locale text-files by default
, i18n: {
defaultLocale: 'en-us'
- , loadPaths: [process.cwd() + '/config/locales']
+ , loadPaths: [path.normalize(cwd + '/config/locales')]
}
// Default to no SSL setup
, ssl: null
14 lib/cluster/master.js
View
@@ -97,10 +97,16 @@ Master.prototype = new (function () {
fileUtils.mkdirP(dir);
types.forEach(function (type) {
- var oldLog = dir + '/' + type + '.log'
- , newLog = dir + '/' + type + '.' + now + '.log';
- if (path.existsSync(oldLog)) {
- fs.renameSync(oldLog, newLog);
+ var currentLog = path.join(dir, type + '.log')
+ , archivedLog = path.join(dir, type + '.' + now + '.log');
+ if (path.existsSync(currentLog)) {
+ try {
+ fs.renameSync(currentLog, archivedLog);
+ }
+ catch(e) {
+ fileUtils.cpR(currentLog, archivedLog);
+ fs.unlinkSync(currentLog);
+ }
}
// After the file is renmaed, create the new logger with the original filename
// e.g., access.log
Paul Golmann

This breaks on linux (means no modules will be loaded at all)! Missing one slash betweeen cwd and modelDir!
cwd has no trailing slash at least on Linux version 2.6.32-30

Matthew Eernisse
Owner

Yes, should have changed the plus to a comma. Just pushed a fix to NPM (v0.3.15). Nice catch. :)

Please sign in to comment.
Something went wrong with that request. Please try again.