Skip to content

Commit

Permalink
refactor: reduce debug logging if unlink was successful (#196)
Browse files Browse the repository at this point in the history
As a way to reduce the amount of debug logging this module produces, we
only emit an unlink debug message if the unlink operation was succesful.

Also, as a better way to correlate unlink issues with a certain
drivelist call, we only report back the result of this module after the
unlink operation ended (sucessfully or not).

Change-Type: patch
See: balena-io/etcher#1600
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
  • Loading branch information
jviotti committed Jul 18, 2017
1 parent bcf8d74 commit 2827803
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions lib/execute.js
Expand Up @@ -74,10 +74,15 @@ const createTemporaryScriptFile = (extension, contents, callback) => {
* @private
*
* @param {String} filename - file path
* @param {Function} callback - callback
*/
const deleteTempFile = (filename) => {
const deleteTempFile = (filename, callback) => {
fs.unlink(filename, (error) => {
debug('unlink', error || 'OK');
if (error) {
debug('unlink', error);
}

callback();
});
};

Expand Down Expand Up @@ -118,26 +123,27 @@ exports.extractAndRun = (script, callback) => {
}, (error, stdout, stderr) => {

// Attempt to clean up, but ignore failure
deleteTempFile(temporaryPath);

if (error) {
error.message += ` (code ${error.code}, signal ${error.signal || 'none'})`;
debug('error:', error);
debug('stderr: %s', stderr);
debug('stdout: %s', stdout);
return callback(error);
}

// Don't throw an error if we get `stderr` output from
// the drive detection scripts at this point, given that
// if the script already exitted with code zero, then
// we consider them warnings that we can safely ignore.
if (stderr.trim().length) {
debug('stderr: %s', stderr);
}

callback(null, stdout);
deleteTempFile(temporaryPath, () => {

if (error) {
error.message += ` (code ${error.code}, signal ${error.signal || 'none'})`;
debug('error:', error);
debug('stderr: %s', stderr);
debug('stdout: %s', stdout);
return callback(error);
}

// Don't throw an error if we get `stderr` output from
// the drive detection scripts at this point, given that
// if the script already exitted with code zero, then
// we consider them warnings that we can safely ignore.
if (stderr.trim().length) {
debug('stderr: %s', stderr);
}

callback(null, stdout);

});
});
});
};

0 comments on commit 2827803

Please sign in to comment.