From 2fa9d6a3c28518e40417fc44bc6e597a2b80d654 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Mon, 25 Jun 2018 19:09:08 -0600 Subject: [PATCH] Clean up a couple DEP0013 spots --- core/file_base_area.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/core/file_base_area.js b/core/file_base_area.js index 7d7ce6fb..faa2dc6a 100644 --- a/core/file_base_area.js +++ b/core/file_base_area.js @@ -280,12 +280,20 @@ function attemptSetEstimatedReleaseDate(fileEntry) { } // a simple log proxy for when we call from oputil.js -function logDebug(obj, msg) { +const logDebug = (obj, msg) => { if(Log) { Log.debug(obj, msg); } } +const logError = (obj, msg) => { + if(Log) { + Log.error(obj, msg); + } else { + console.error(`${msg}: ${JSON.stringify(obj)}`); + } +} + function extractAndProcessDescFiles(fileEntry, filePath, archiveEntries, cb) { async.waterfall( [ @@ -709,8 +717,12 @@ function scanFile(filePath, options, iterator, cb) { const nextChunk = () => { fs.read(fd, buffer, 0, chunkSize, null, (err, bytesRead) => { if(err) { - fs.close(fd); - return readErrorCallIter(err, callback); + return fs.close(fd, closeErr => { + if(closeErr) { + logError( { filePath, error : err.message }, 'Failed to close file'); + } + return readErrorCallIter(err, callback); + }); } if(0 === bytesRead) { @@ -729,8 +741,12 @@ function scanFile(filePath, options, iterator, cb) { } stepInfo.step = 'hash_finish'; - fs.close(fd); - return callIter(callback); + return fs.close(fd, closeErr => { + if(closeErr) { + logError( { filePath, error : err.message }, 'Failed to close file'); + } + return callIter(callback); + }); } stepInfo.bytesProcessed += bytesRead;