Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Only validate error argument if it's passed
  • Loading branch information
iansu committed Jun 13, 2019
commit 4c372b65f7abf93163b4028fc0572ca339a765e9
16 changes: 10 additions & 6 deletions lib/internal/shutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ function rmtreeSync(path, options) {

validatePath(path);

let st;

try {
var st = options.lstatSync(path);
st = options.lstatSync(path);
} catch (er) {
if (er.code === 'ENOENT') return;

Expand Down Expand Up @@ -176,7 +178,7 @@ function getOptions(options) {
function fixWinEPERM(path, options, error, callback) {
validatePath(path);
validateOptions(options);
validateError(error);
if (error) validateError(error);
validateCallback(callback);

options.chmod(path, _0666, function(er2) {
Expand All @@ -193,7 +195,9 @@ function fixWinEPERM(path, options, error, callback) {
function fixWinEPERMSync(path, options, error) {
validatePath(path);
validateOptions(options);
validateError(error);
if (error) validateError(error);

let stats;

try {
options.chmodSync(path, _0666);
Expand All @@ -203,7 +207,7 @@ function fixWinEPERMSync(path, options, error) {
}

try {
var stats = options.statSync(path);
stats = options.statSync(path);
} catch (er3) {
if (er3.code === 'ENOENT') return;
else throw error;
Expand All @@ -216,7 +220,7 @@ function fixWinEPERMSync(path, options, error) {
function rmdir(path, options, originalEr, callback) {
validatePath(path);
validateOptions(options);
validateError(originalEr);
if (originalEr) validateError(originalEr);
validateCallback(callback);

// Try to rmdir first, and only readdir on ENOTEMPTY or EEXIST (SunOS)
Expand All @@ -237,7 +241,7 @@ function rmdir(path, options, originalEr, callback) {
function rmdirSync(path, options, originalEr) {
validatePath(path);
validateOptions(options);
validateError(originalEr);
if (originalEr) validateError(originalEr);

try {
options.rmdirSync(path);
Expand Down
5 changes: 2 additions & 3 deletions test/parallel/test-shutil-rmtree.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
'use strict';
require('../common');
const tmpdir = require('../common/tmpdir');

const fs = require('fs');
const path = require('path');
const assert = require('assert');
const shutil = require('shutil');

const common = require('../common');
const tmpdir = common.tmpdir;

const tmpDir = tmpdir.path;
const baseDir = path.join(tmpDir, 'shutil-rmtree');

Expand Down