diff --git a/bin/sinopia b/bin/sinopia index 46631cb09..e5e6a77ea 100755 --- a/bin/sinopia +++ b/bin/sinopia @@ -14,21 +14,24 @@ commander .version(pkg.version) .parse(process.argv); -var config; +var config, config_path; if (commander.config) { - config = yaml.safeLoad(fs.readFileSync(commander.config, 'utf8')); + config_path = commander.config; + config = yaml.safeLoad(fs.readFileSync(config_path, 'utf8')); } else { + config_path = './config.yaml'; try { - config = yaml.safeLoad(fs.readFileSync('./config.yaml', 'utf8')); + config = yaml.safeLoad(fs.readFileSync(config_path, 'utf8')); } catch(err) { var created_config = require('../lib/config_gen')(); config = yaml.safeLoad(created_config.yaml); console.log('starting with default config, use user: "%s", pass: "%s" to authenticate', created_config.user, created_config.pass); - fs.writeFileSync('./config.yaml', created_config.yaml); + fs.writeFileSync(config_path, created_config.yaml); } } if (!config.user_agent) config.user_agent = 'Sinopia/'+pkg.version; +if (!config.self_path) config.self_path = config_path; var hostport = commander.listen.split(':'); if (hostport.length < 2) { diff --git a/lib/st-local.js b/lib/st-local.js index 175c92f66..bba7e38d5 100644 --- a/lib/st-local.js +++ b/lib/st-local.js @@ -1,6 +1,7 @@ var fs = require('fs'); var semver = require('semver'); var through = require('through'); +var Path = require('path'); var fs_storage = require('./fs-storage'); var UError = require('./error').UserError; var utils = require('./utils'); @@ -9,6 +10,7 @@ var info_file = 'package.json'; function Storage(config) { if (!(this instanceof Storage)) return new Storage(config); this.config = config; + var path = Path.resolve(Path.dirname(this.config.self_path), this.config.storage); this.storage = new fs_storage(this.config.storage); return this; }