Skip to content

Commit

Permalink
Uses execSync to return the result of callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Karanvir Kang authored Mar 17, 2017
1 parent 4e2997f commit aa68752
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,30 @@ var debug = gutil.log;
* @param {string} path - Folder from which read-only flag needs to be cleared
* @param {function} callback - Callback function to invoke
* @param {Object} opts - Plugin options { isFile, debug }
* @return {Object} callback result if any
*/
function clearReadOnly(path, callback, providedOptions) {
var options = getOptions(providedOptions);
debug = options.debug ? gutil.log : function (){};
debug(moduleName, 'Clearing read-only flag for path: ' + path + '...');


var callbackResult;
var clearReadOnlyCommand = getCommand(path, !options.isFile);
cp.exec(clearReadOnlyCommand, function (error) {
// We only care about errors for this command
if (error) {
// Handle failure scenario
debug(moduleName, error);
throw new gutil.PluginError(moduleName, 'Failed to clear read only flag.');
} else {
// Mark this asynchronous task as completed
debug(moduleName, 'Cleared read-only flag for path: ' + path);

// Invoke callback
if (callback) {
callback();
}
}
});
try
{
cp.execSync(clearReadOnlyCommand);
// Mark this asynchronous task as completed
debug(moduleName, 'Cleared read-only flag for path: ' + path);
if (typeof(callback) == 'function') {
callbackResult = callback();
}
} catch (error) {
// Handle failure scenario
debug(moduleName, error);
throw new gutil.PluginError(moduleName, 'Failed to clear read only flag.');
}

return callbackResult;
}

/**
Expand Down

0 comments on commit aa68752

Please sign in to comment.