Skip to content
Merged
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
82 changes: 28 additions & 54 deletions ext/node/polyfills/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,12 @@ import {
constants as fsUtilConstants,
copyObject,
Dirent,
emitRecursiveRmdirWarning,
getOptions,
getValidatedFd,
getValidatedPath,
getValidatedPathToString,
getValidMode,
kMaxUserId,
type RmOptions,
Stats,
stringToFlags,
toUnixTimestamp as _toUnixTimestamp,
Expand Down Expand Up @@ -139,8 +137,8 @@ import {
op_node_statfs_sync,
} from "ext:core/ops";
import {
ERR_FS_RMDIR_ENOTDIR,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
Comment thread
bartlomieju marked this conversation as resolved.
uvException,
} from "ext:deno_node/internal/errors.ts";
import { toUnixTimestamp } from "ext:deno_node/internal/fs/utils.mjs";
Expand Down Expand Up @@ -1737,26 +1735,6 @@ type rmdirOptions = {

type rmdirCallback = (err?: Error) => void;

const rmdirRecursive =
(path: string, callback: rmdirCallback) =>
(err: Error | false | null, options?: RmOptions) => {
if (err === false) {
return callback(new ERR_FS_RMDIR_ENOTDIR(path));
}
if (err) {
return callback(err);
}

PromisePrototypeThen(
Deno.remove(path, { recursive: options?.recursive }),
(_) => callback(),
(err: Error) =>
callback(
denoErrorToNodeError(err, { syscall: "rmdir", path }),
),
);
};

function rmdir(
path: string | Buffer | URL,
callback: rmdirCallback,
Expand All @@ -1775,44 +1753,40 @@ function rmdir(
callback = options;
options = undefined;
}
validateFunction(callback, "cb");
path = getValidatedPathToString(path);

if (options?.recursive) {
emitRecursiveRmdirWarning();
validateRmOptions(
path,
{ ...options, force: false },
true,
rmdirRecursive(path, callback),
);
} else {
validateRmdirOptions(options);
PromisePrototypeThen(
op_node_rmdir(path),
(_) => callback(),
(err: Error) =>
callback(
denoErrorToNodeError(err, { syscall: "rmdir", path }),
),
if (options?.recursive !== undefined) {
// The `recursive` option was deprecated and removed in Node. Throw with a
// clear message rather than silently doing the wrong thing.
throw new ERR_INVALID_ARG_VALUE(
Comment thread
bartlomieju marked this conversation as resolved.
"options.recursive",
options.recursive,
"is no longer supported",
);
}

validateFunction(callback, "cb");
path = getValidatedPathToString(path);

validateRmdirOptions(options);
PromisePrototypeThen(
op_node_rmdir(path),
(_) => callback(),
(err: Error) =>
callback(
denoErrorToNodeError(err, { syscall: "rmdir", path }),
),
);
}

function rmdirSync(path: string | Buffer | URL, options?: rmdirOptions) {
path = getValidatedPathToString(path);
if (options?.recursive) {
emitRecursiveRmdirWarning();
const optionsOrFalse = validateRmOptionsSync(path, {
...options,
force: false,
}, true);
if (optionsOrFalse === false) {
throw new ERR_FS_RMDIR_ENOTDIR(path);
}
return Deno.removeSync(path, {
recursive: true,
});

if (options?.recursive !== undefined) {
throw new ERR_INVALID_ARG_VALUE(
"options.recursive",
options.recursive,
"is no longer supported",
);
}

validateRmdirOptions(options);
Expand Down
1 change: 1 addition & 0 deletions tests/node_compat/config.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,7 @@
"windows": false
},
"parallel/test-fs-rmSync-special-char.js": {},
"parallel/test-fs-rmdir-recursive-error.js": {},
"parallel/test-fs-rmdir-throws-not-found.js": {},
"parallel/test-fs-rmdir-type-check.js": {},
"parallel/test-fs-sir-writes-alot.js": {},
Expand Down
Loading