noent fix

This commit is contained in:
Matias Alejo Garcia 2015-02-24 16:06:07 -03:00
parent c0a7121d29
commit ebbf493935
3 changed files with 39 additions and 7 deletions

View File

@ -53,12 +53,30 @@ Utils.getClient = function(args) {
if (args.password) {
return cb(args.password);
} else {
read({ prompt: 'Password: ', silent: true }, function(er, password) {
read({
prompt: 'Password for ' + args.file + ' : ',
silent: true
}, function(er, password) {
return cb(password);
})
}
});
c.on('needNewPassword', function(cb) {
if (args.password) {
return cb(args.password);
} else {
read({
prompt: 'New Password: ',
silent: true
}, function(er, password) {
return cb(password);
})
}
});
return c;
}

View File

@ -238,7 +238,7 @@ API.prototype._processWcdBeforeWrite = function(wcd, cb) {
if (this.noPasswdAccess == 'full') {
return cb(null, wcd);
} else {
this.emit('needPassword', function(password) {
this.emit('needNewPassword', function(password) {
if (!password) return cb('No password given');
var ewcd = WalletUtils.encryptWallet(wcd, self.noPasswdAccess, password);
return cb(null, ewcd);
@ -254,7 +254,8 @@ API.prototype._load = function(opts, cb) {
this.storage.load(function(err, rawdata) {
if (err || !rawdata) {
return cb(err || 'wcd file not found.');
if (err && err.code == 'ENOENT') err = 'NOTFOUND';
return cb(err || 'NOTFOUND');
}
self._processWcdAfterRead(rawdata, opts.requiredAccess, cb);
});
@ -382,7 +383,12 @@ API.prototype.createWallet = function(walletName, copayerName, m, n, network, cb
if (!_.contains(['testnet', 'livenet'], network))
return cb('Invalid network');
this.storage.load(function(err, wcd) {
this._load({
requiredAccess: 'readonly',
}, function(err, wcd) {
if (err && err != 'NOTFOUND')
return cb(err);
if (wcd && wcd.n)
return cb(self.storage.getName() + ' already contains a wallet');
@ -457,7 +463,12 @@ API.prototype.reCreateWallet = function(walletName, cb) {
API.prototype.joinWallet = function(secret, copayerName, cb) {
var self = this;
this.storage.load(function(err, wcd) {
this._load({
requiredAccess: 'readonly'
}, function(err, wcd) {
if (err && err != 'NOTFOUND')
return cb(err);
if (wcd && wcd.n)
return cb(self.storage.getName() + ' already contains a wallet');

View File

@ -65,7 +65,7 @@ var fsmock = {};
var content = {};
fsmock.readFile = function(name, enc, cb) {
if (!content || _.isEmpty(content[name]))
return cb('empty');
return cb('NOTFOUND');
return cb(null, content[name]);
};
@ -227,6 +227,10 @@ describe('client API ', function() {
clients[i].on('needPassword', function(cb) {
return cb('1234#$@#%F,./.**');
});
clients[i].on('needNewPassword', function(cb) {
return cb('1234#$@#%F,./.**');
});
});
});
@ -637,7 +641,6 @@ describe('client API ', function() {
}, function(err, str) {
proxy.import(str, function(err) {
should.not.exist(err);
proxy.createWallet('1', '2', 1, 1, 'testnet',
function(err) {
should.not.exist(err);