diff --git a/app/controllers/noms.js b/app/controllers/noms.js index 85b6850..e43680e 100644 --- a/app/controllers/noms.js +++ b/app/controllers/noms.js @@ -15,26 +15,30 @@ noms.get = function (login, cb) { if (nom.length >= 1) { cb(nom.nom) } else { - found = false - stream = fs.createReadStream('config/passwd') - transform = new LineTransform() - stream.pipe(transform) - transform.on('data', function (line) { - ex = line.split(':') - if (ex[0] == login) { // Si trouvé - found = true - cb(ex[4]) + passwdF = 'config/passwd' + fs.exists(passwdF, function (exists) { + found = false + if (exists) { + stream = fs.createReadStream(passwdF) + transform = new LineTransform() + stream.pipe(transform) + transform.on('data', function (line) { + ex = line.split(':') + if (ex[0] == login) { // Si trouvé + found = true + cb(ex[4]) + } + }) + transform.on('end', function () { + if (!found) { + cb(false) + } + }) + } else { + console.error("Impossible de trouver le fichier passwd") + cb(login.toUpperCase()) } }) - transform.on('end', function () { - if (!found) { - cb(false) - } - }) - transform.on('error', function (e) { - console.error("Error while fetching name", e) - cb(login.toUpperCase()) - }) } } }) -- libgit2 0.21.2