From 725cb3f7d1204ff291c275a0719e631dc3410c57 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sat, 21 Mar 2015 13:29:27 +0100 Subject: [PATCH] Vérification de la présence de passwd --- app/controllers/noms.js | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) 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