test: use tmpdir.resolve() in fs tests

PR-URL: https://github.com/nodejs/node/pull/49126
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
Livia Medeiros 2023-08-15 22:45:24 +09:00 committed by GitHub
parent 74e0ca3f49
commit 6a68794577
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
52 changed files with 169 additions and 209 deletions

View File

@ -13,15 +13,14 @@ if (common.isIBMi)
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const { internalBinding } = require('internal/test/binding');
const { UV_ENOENT } = internalBinding('uv');
const tmpdir = require('../common/tmpdir');
const doesNotExist = path.join(tmpdir.path, '__this_should_not_exist');
const readOnlyFile = path.join(tmpdir.path, 'read_only_file');
const readWriteFile = path.join(tmpdir.path, 'read_write_file');
const doesNotExist = tmpdir.resolve('__this_should_not_exist');
const readOnlyFile = tmpdir.resolve('read_only_file');
const readWriteFile = tmpdir.resolve('read_write_file');
function createFileWithPerms(file, mode) {
fs.writeFileSync(file, '');

View File

@ -22,7 +22,6 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const join = require('path').join;
const fs = require('fs');
const currentFileData = 'ABCD';
@ -40,7 +39,7 @@ const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
// Test that empty file will be created and have content added.
const filename = join(tmpdir.path, 'append-sync.txt');
const filename = tmpdir.resolve('append-sync.txt');
fs.appendFileSync(filename, data);
@ -49,7 +48,7 @@ const fileData = fs.readFileSync(filename);
assert.strictEqual(Buffer.byteLength(data), fileData.length);
// Test that appends data to a non empty file.
const filename2 = join(tmpdir.path, 'append-sync2.txt');
const filename2 = tmpdir.resolve('append-sync2.txt');
fs.writeFileSync(filename2, currentFileData);
fs.appendFileSync(filename2, data);
@ -60,7 +59,7 @@ assert.strictEqual(Buffer.byteLength(data) + currentFileData.length,
fileData2.length);
// Test that appendFileSync accepts buffers.
const filename3 = join(tmpdir.path, 'append-sync3.txt');
const filename3 = tmpdir.resolve('append-sync3.txt');
fs.writeFileSync(filename3, currentFileData);
const buf = Buffer.from(data, 'utf8');
@ -70,7 +69,7 @@ const fileData3 = fs.readFileSync(filename3);
assert.strictEqual(buf.length + currentFileData.length, fileData3.length);
const filename4 = join(tmpdir.path, 'append-sync4.txt');
const filename4 = tmpdir.resolve('append-sync4.txt');
fs.writeFileSync(filename4, currentFileData, common.mustNotMutateObjectDeep({ mode: m }));
[
@ -95,7 +94,7 @@ assert.strictEqual(Buffer.byteLength(String(num)) + currentFileData.length,
fileData4.length);
// Test that appendFile accepts file descriptors.
const filename5 = join(tmpdir.path, 'append-sync5.txt');
const filename5 = tmpdir.resolve('append-sync5.txt');
fs.writeFileSync(filename5, currentFileData);
const filename5fd = fs.openSync(filename5, 'a+', 0o600);

View File

@ -23,7 +23,6 @@
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const join = require('path').join;
const tmpdir = require('../common/tmpdir');
@ -43,7 +42,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
// Test that empty file will be created and have content added (callback API).
{
const filename = join(tmpdir.path, 'append.txt');
const filename = tmpdir.resolve('append.txt');
fs.appendFile(filename, s, common.mustSucceed(() => {
fs.readFile(filename, common.mustSucceed((buffer) => {
@ -54,7 +53,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
// Test that empty file will be created and have content added (promise API).
{
const filename = join(tmpdir.path, 'append-promise.txt');
const filename = tmpdir.resolve('append-promise.txt');
fs.promises.appendFile(filename, s)
.then(common.mustCall(() => fs.promises.readFile(filename)))
@ -66,7 +65,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
// Test that appends data to a non-empty file (callback API).
{
const filename = join(tmpdir.path, 'append-non-empty.txt');
const filename = tmpdir.resolve('append-non-empty.txt');
fs.writeFileSync(filename, currentFileData);
fs.appendFile(filename, s, common.mustSucceed(() => {
@ -79,7 +78,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
// Test that appends data to a non-empty file (promise API).
{
const filename = join(tmpdir.path, 'append-non-empty-promise.txt');
const filename = tmpdir.resolve('append-non-empty-promise.txt');
fs.writeFileSync(filename, currentFileData);
fs.promises.appendFile(filename, s)
@ -93,7 +92,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
// Test that appendFile accepts buffers (callback API).
{
const filename = join(tmpdir.path, 'append-buffer.txt');
const filename = tmpdir.resolve('append-buffer.txt');
fs.writeFileSync(filename, currentFileData);
const buf = Buffer.from(s, 'utf8');
@ -107,7 +106,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
// Test that appendFile accepts buffers (promises API).
{
const filename = join(tmpdir.path, 'append-buffer-promises.txt');
const filename = tmpdir.resolve('append-buffer-promises.txt');
fs.writeFileSync(filename, currentFileData);
const buf = Buffer.from(s, 'utf8');
@ -126,7 +125,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
code: 'ERR_INVALID_ARG_TYPE',
message: /"data"|"buffer"/
};
const filename = join(tmpdir.path, 'append-invalid-data.txt');
const filename = tmpdir.resolve('append-invalid-data.txt');
assert.throws(
() => fs.appendFile(filename, data, common.mustNotCall()),
@ -154,7 +153,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
// Test that appendFile accepts file descriptors (callback API).
{
const filename = join(tmpdir.path, 'append-descriptors.txt');
const filename = tmpdir.resolve('append-descriptors.txt');
fs.writeFileSync(filename, currentFileData);
fs.open(filename, 'a+', common.mustSucceed((fd) => {
@ -171,7 +170,7 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
// Test that appendFile accepts file descriptors (promises API).
{
const filename = join(tmpdir.path, 'append-descriptors-promises.txt');
const filename = tmpdir.resolve('append-descriptors-promises.txt');
fs.writeFileSync(filename, currentFileData);
let fd;
@ -190,5 +189,5 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
}
assert.throws(
() => fs.appendFile(join(tmpdir.path, 'append6.txt'), console.log),
() => fs.appendFile(tmpdir.resolve('append6.txt'), console.log),
{ code: 'ERR_INVALID_ARG_TYPE' });

View File

@ -2,10 +2,9 @@
const common = require('../common');
const assert = require('node:assert');
const fs = require('node:fs');
const path = require('node:path');
const tmpdir = require('../common/tmpdir');
const testPath = path.join(tmpdir.path, 'assert-encoding-error');
const testPath = tmpdir.resolve('assert-encoding-error');
const options = 'test';
const expectedError = {
code: 'ERR_INVALID_ARG_VALUE',

View File

@ -4,14 +4,13 @@ const common = require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
fs.access(Buffer.from(tmpdir.path), common.mustSucceed());
const buf = Buffer.from(path.join(tmpdir.path, 'a.txt'));
const buf = Buffer.from(tmpdir.resolve('a.txt'));
fs.open(buf, 'w+', common.mustSucceed((fd) => {
assert(fd);
fs.close(fd, common.mustSucceed());

View File

@ -4,7 +4,6 @@
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
let mode;
@ -26,7 +25,7 @@ function test(mode, asString) {
(mode | maskToIgnore).toString(8) : (mode | maskToIgnore);
{
const file = path.join(tmpdir.path, `chmod-async-${suffix}.txt`);
const file = tmpdir.resolve(`chmod-async-${suffix}.txt`);
fs.writeFileSync(file, 'test', 'utf-8');
fs.chmod(file, input, common.mustSucceed(() => {
@ -35,7 +34,7 @@ function test(mode, asString) {
}
{
const file = path.join(tmpdir.path, `chmodSync-${suffix}.txt`);
const file = tmpdir.resolve(`chmodSync-${suffix}.txt`);
fs.writeFileSync(file, 'test', 'utf-8');
fs.chmodSync(file, input);
@ -43,7 +42,7 @@ function test(mode, asString) {
}
{
const file = path.join(tmpdir.path, `fchmod-async-${suffix}.txt`);
const file = tmpdir.resolve(`fchmod-async-${suffix}.txt`);
fs.writeFileSync(file, 'test', 'utf-8');
fs.open(file, 'w', common.mustSucceed((fd) => {
fs.fchmod(fd, input, common.mustSucceed(() => {
@ -54,7 +53,7 @@ function test(mode, asString) {
}
{
const file = path.join(tmpdir.path, `fchmodSync-${suffix}.txt`);
const file = tmpdir.resolve(`fchmodSync-${suffix}.txt`);
fs.writeFileSync(file, 'test', 'utf-8');
const fd = fs.openSync(file, 'w');
@ -65,8 +64,8 @@ function test(mode, asString) {
}
if (fs.lchmod) {
const link = path.join(tmpdir.path, `lchmod-src-${suffix}`);
const file = path.join(tmpdir.path, `lchmod-dest-${suffix}`);
const link = tmpdir.resolve(`lchmod-src-${suffix}`);
const file = tmpdir.resolve(`lchmod-dest-${suffix}`);
fs.writeFileSync(file, 'test', 'utf-8');
fs.symlinkSync(file, link);
@ -76,8 +75,8 @@ function test(mode, asString) {
}
if (fs.lchmodSync) {
const link = path.join(tmpdir.path, `lchmodSync-src-${suffix}`);
const file = path.join(tmpdir.path, `lchmodSync-dest-${suffix}`);
const link = tmpdir.resolve(`lchmodSync-src-${suffix}`);
const file = tmpdir.resolve(`lchmodSync-dest-${suffix}`);
fs.writeFileSync(file, 'test', 'utf-8');
fs.symlinkSync(file, link);

View File

@ -22,7 +22,6 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
let mode_async;
@ -74,8 +73,8 @@ if (common.isWindows) {
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
const file1 = path.join(tmpdir.path, 'a.js');
const file2 = path.join(tmpdir.path, 'a1.js');
const file1 = tmpdir.resolve('a.js');
const file2 = tmpdir.resolve('a1.js');
// Create file1.
fs.closeSync(fs.openSync(file1, 'w'));
@ -123,7 +122,7 @@ fs.open(file2, 'w', common.mustSucceed((fd) => {
// lchmod
if (fs.lchmod) {
const link = path.join(tmpdir.path, 'symbolic-link');
const link = tmpdir.resolve('symbolic-link');
fs.symlinkSync(file2, link);

View File

@ -16,14 +16,13 @@ tmpdir.refresh();
const assert = require('assert');
const fs = require('fs');
const path = require('path');
let n = 0;
function beforeEach() {
n++;
const source = path.join(tmpdir.path, `source${n}`);
const dest = path.join(tmpdir.path, `dest${n}`);
const source = tmpdir.resolve(`source${n}`);
const dest = tmpdir.resolve(`dest${n}`);
fs.writeFileSync(source, 'source');
fs.writeFileSync(dest, 'dest');
fs.chmodSync(dest, '444');

View File

@ -10,9 +10,8 @@ const {
UV_ENOENT,
UV_EEXIST
} = internalBinding('uv');
const path = require('path');
const src = fixtures.path('a.js');
const dest = path.join(tmpdir.path, 'copyfile.out');
const dest = tmpdir.resolve('copyfile.out');
const {
COPYFILE_EXCL,
COPYFILE_FICLONE,

View File

@ -25,7 +25,7 @@ tmpdir.refresh();
let dirc = 0;
function nextdir() {
return join(tmpdir.path, `copy_${++dirc}`);
return tmpdir.resolve(`copy_${++dirc}`);
}
// Synchronous implementation of copy.

View File

@ -26,16 +26,15 @@ const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
tmpdir.refresh();
const nonexistentFile = path.join(tmpdir.path, 'non-existent');
const nonexistentDir = path.join(tmpdir.path, 'non-existent', 'foo', 'bar');
const existingFile = path.join(tmpdir.path, 'existingFile.js');
const existingFile2 = path.join(tmpdir.path, 'existingFile2.js');
const existingDir = path.join(tmpdir.path, 'dir');
const nonexistentFile = tmpdir.resolve('non-existent');
const nonexistentDir = tmpdir.resolve('non-existent', 'foo', 'bar');
const existingFile = tmpdir.resolve('existingFile.js');
const existingFile2 = tmpdir.resolve('existingFile2.js');
const existingDir = tmpdir.resolve('dir');
const existingDir2 = fixtures.path('keys');
fs.mkdirSync(existingDir);
fs.writeFileSync(existingFile, 'test', 'utf-8');
@ -297,7 +296,7 @@ function re(literals, ...values) {
return true;
};
const destFile = path.join(tmpdir.path, 'foo');
const destFile = tmpdir.resolve('foo');
fs.rename(nonexistentFile, destFile, common.mustCall(validateError));
assert.throws(

View File

@ -2,7 +2,6 @@
require('../common');
const assert = require('assert');
const fs = require('fs');
const join = require('path').join;
const {
O_CREAT = 0,
@ -18,7 +17,7 @@ tmpdir.refresh();
// Run this test on all platforms. While UV_FS_O_FILEMAP is only available on
// Windows, it should be silently ignored on other platforms.
const filename = join(tmpdir.path, 'fmap.txt');
const filename = tmpdir.resolve('fmap.txt');
const text = 'Memory File Mapping Test';
const mw = UV_FS_O_FILEMAP | O_TRUNC | O_CREAT | O_WRONLY;

View File

@ -26,10 +26,9 @@ const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');
const fs = require('fs');
const path = require('path');
const fileFixture = fixtures.path('a.js');
const fileTemp = path.join(tmpdir.path, 'a.js');
const fileTemp = tmpdir.resolve('a.js');
// Copy fixtures to temp.
tmpdir.refresh();

View File

@ -9,8 +9,8 @@ import glob from 'internal/fs/glob';
tmpdir.refresh();
const fixtureDir = resolve(tmpdir.path, 'fixtures');
const absDir = resolve(tmpdir.path, 'abs');
const fixtureDir = tmpdir.resolve('fixtures');
const absDir = tmpdir.resolve('abs');
async function setup() {
await mkdir(fixtureDir, { recursive: true });

View File

@ -51,7 +51,7 @@ const { promises } = fs;
});
if (!common.isWindows) {
const testFile = path.join(tmpdir.path, path.basename(__filename));
const testFile = tmpdir.resolve(path.basename(__filename));
const uid = process.geteuid();
const gid = process.getegid();

View File

@ -1,15 +1,14 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
// Test creating and reading hard link
const srcPath = path.join(tmpdir.path, 'hardlink-target.txt');
const dstPath = path.join(tmpdir.path, 'link1.js');
const srcPath = tmpdir.resolve('hardlink-target.txt');
const dstPath = tmpdir.resolve('link1.js');
fs.writeFileSync(srcPath, 'hello world');
function callback(err) {

View File

@ -31,7 +31,7 @@ const tmpdir = require('../common/tmpdir');
// Make a path that will be at least 260 chars long.
const fileNameLen = Math.max(260 - tmpdir.path.length - 1, 1);
const fileName = path.join(tmpdir.path, 'x'.repeat(fileNameLen));
const fileName = tmpdir.resolve('x'.repeat(fileNameLen));
const fullPath = path.resolve(fileName);
tmpdir.refresh();

View File

@ -4,7 +4,6 @@
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
if (common.isWindows) {
@ -24,13 +23,13 @@ function test(mode, asString) {
(mode | maskToIgnore).toString(8) : (mode | maskToIgnore);
{
const dir = path.join(tmpdir.path, `mkdirSync-${suffix}`);
const dir = tmpdir.resolve(`mkdirSync-${suffix}`);
fs.mkdirSync(dir, input);
assert.strictEqual(fs.statSync(dir).mode & 0o777, mode);
}
{
const dir = path.join(tmpdir.path, `mkdir-${suffix}`);
const dir = tmpdir.resolve(`mkdir-${suffix}`);
fs.mkdir(dir, input, common.mustSucceed(() => {
assert.strictEqual(fs.statSync(dir).mode & 0o777, mode);
}));

View File

@ -41,7 +41,7 @@ function makeDirectoryWritable(dir) {
// Synchronous API should return an EACCESS error with path populated.
{
const dir = path.join(tmpdir.path, `mkdirp_${n++}`);
const dir = tmpdir.resolve(`mkdirp_${n++}`);
fs.mkdirSync(dir);
const codeExpected = makeDirectoryReadOnly(dir);
let err = null;
@ -58,7 +58,7 @@ function makeDirectoryWritable(dir) {
// Asynchronous API should return an EACCESS error with path populated.
{
const dir = path.join(tmpdir.path, `mkdirp_${n++}`);
const dir = tmpdir.resolve(`mkdirp_${n++}`);
fs.mkdirSync(dir);
const codeExpected = makeDirectoryReadOnly(dir);
fs.mkdir(path.join(dir, '/bar'), { recursive: true }, (err) => {

View File

@ -2,10 +2,9 @@
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
const d = path.join(tmpdir.path, 'dir');
const d = tmpdir.resolve('dir');
tmpdir.refresh();

View File

@ -35,7 +35,7 @@ function nextdir() {
// fs.mkdir creates directory using assigned path
{
const pathname = path.join(tmpdir.path, nextdir());
const pathname = tmpdir.resolve(nextdir());
fs.mkdir(pathname, common.mustCall(function(err) {
assert.strictEqual(err, null);
@ -45,7 +45,7 @@ function nextdir() {
// fs.mkdir creates directory with assigned mode value
{
const pathname = path.join(tmpdir.path, nextdir());
const pathname = tmpdir.resolve(nextdir());
fs.mkdir(pathname, 0o777, common.mustCall(function(err) {
assert.strictEqual(err, null);
@ -55,7 +55,7 @@ function nextdir() {
// fs.mkdir creates directory with mode passed as an options object
{
const pathname = path.join(tmpdir.path, nextdir());
const pathname = tmpdir.resolve(nextdir());
fs.mkdir(pathname, common.mustNotMutateObjectDeep({ mode: 0o777 }), common.mustCall(function(err) {
assert.strictEqual(err, null);
@ -65,7 +65,7 @@ function nextdir() {
// fs.mkdirSync creates directory with mode passed as an options object
{
const pathname = path.join(tmpdir.path, nextdir());
const pathname = tmpdir.resolve(nextdir());
fs.mkdirSync(pathname, common.mustNotMutateObjectDeep({ mode: 0o777 }));
@ -74,7 +74,7 @@ function nextdir() {
// mkdirSync successfully creates directory from given path
{
const pathname = path.join(tmpdir.path, nextdir());
const pathname = tmpdir.resolve(nextdir());
fs.mkdirSync(pathname);
@ -103,7 +103,7 @@ function nextdir() {
// mkdirpSync when both top-level, and sub-folders do not exist.
{
const pathname = path.join(tmpdir.path, nextdir(), nextdir());
const pathname = tmpdir.resolve(nextdir(), nextdir());
fs.mkdirSync(pathname, common.mustNotMutateObjectDeep({ recursive: true }));
@ -114,7 +114,7 @@ function nextdir() {
// mkdirpSync when folder already exists.
{
const pathname = path.join(tmpdir.path, nextdir(), nextdir());
const pathname = tmpdir.resolve(nextdir(), nextdir());
fs.mkdirSync(pathname, { recursive: true });
// Should not cause an error.
@ -136,7 +136,7 @@ function nextdir() {
// mkdirpSync when path is a file.
{
const pathname = path.join(tmpdir.path, nextdir(), nextdir());
const pathname = tmpdir.resolve(nextdir(), nextdir());
fs.mkdirSync(path.dirname(pathname));
fs.writeFileSync(pathname, '', 'utf8');
@ -154,7 +154,7 @@ function nextdir() {
// mkdirpSync when part of the path is a file.
{
const filename = path.join(tmpdir.path, nextdir(), nextdir());
const filename = tmpdir.resolve(nextdir(), nextdir());
const pathname = path.join(filename, nextdir(), nextdir());
fs.mkdirSync(path.dirname(filename));
@ -174,7 +174,7 @@ function nextdir() {
// `mkdirp` when folder does not yet exist.
{
const pathname = path.join(tmpdir.path, nextdir(), nextdir());
const pathname = tmpdir.resolve(nextdir(), nextdir());
fs.mkdir(pathname, common.mustNotMutateObjectDeep({ recursive: true }), common.mustCall(function(err) {
assert.strictEqual(err, null);
@ -185,7 +185,7 @@ function nextdir() {
// `mkdirp` when path is a file.
{
const pathname = path.join(tmpdir.path, nextdir(), nextdir());
const pathname = tmpdir.resolve(nextdir(), nextdir());
fs.mkdirSync(path.dirname(pathname));
fs.writeFileSync(pathname, '', 'utf8');
@ -198,7 +198,7 @@ function nextdir() {
// `mkdirp` when part of the path is a file.
{
const filename = path.join(tmpdir.path, nextdir(), nextdir());
const filename = tmpdir.resolve(nextdir(), nextdir());
const pathname = path.join(filename, nextdir(), nextdir());
fs.mkdirSync(path.dirname(filename));
@ -218,7 +218,7 @@ function nextdir() {
// mkdirpSync dirname loop
// XXX: windows and smartos have issues removing a directory that you're in.
if (common.isMainThread && (common.isLinux || common.isOSX)) {
const pathname = path.join(tmpdir.path, nextdir());
const pathname = tmpdir.resolve(nextdir());
fs.mkdirSync(pathname);
process.chdir(pathname);
fs.rmdirSync(pathname);
@ -240,7 +240,7 @@ if (common.isMainThread && (common.isLinux || common.isOSX)) {
// mkdirSync and mkdir require options.recursive to be a boolean.
// Anything else generates an error.
{
const pathname = path.join(tmpdir.path, nextdir());
const pathname = tmpdir.resolve(nextdir());
['', 1, {}, [], null, Symbol('test'), () => {}].forEach((recursive) => {
const received = common.invalidArgTypeHelper(recursive);
assert.throws(
@ -268,8 +268,8 @@ if (common.isMainThread && (common.isLinux || common.isOSX)) {
{
const dir1 = nextdir();
const dir2 = nextdir();
const firstPathCreated = path.join(tmpdir.path, dir1);
const pathname = path.join(tmpdir.path, dir1, dir2);
const firstPathCreated = tmpdir.resolve(dir1);
const pathname = tmpdir.resolve(dir1, dir2);
fs.mkdir(pathname, common.mustNotMutateObjectDeep({ recursive: true }), common.mustCall(function(err, path) {
assert.strictEqual(err, null);
@ -283,8 +283,8 @@ if (common.isMainThread && (common.isLinux || common.isOSX)) {
{
const dir1 = nextdir();
const dir2 = nextdir();
const pathname = path.join(tmpdir.path, dir1, dir2);
fs.mkdirSync(path.join(tmpdir.path, dir1));
const pathname = tmpdir.resolve(dir1, dir2);
fs.mkdirSync(tmpdir.resolve(dir1));
fs.mkdir(pathname, common.mustNotMutateObjectDeep({ recursive: true }), common.mustCall(function(err, path) {
assert.strictEqual(err, null);
assert.strictEqual(fs.existsSync(pathname), true);
@ -297,8 +297,8 @@ if (common.isMainThread && (common.isLinux || common.isOSX)) {
{
const dir1 = nextdir();
const dir2 = nextdir();
const pathname = path.join(tmpdir.path, dir1, dir2);
fs.mkdirSync(path.join(tmpdir.path, dir1, dir2), common.mustNotMutateObjectDeep({ recursive: true }));
const pathname = tmpdir.resolve(dir1, dir2);
fs.mkdirSync(tmpdir.resolve(dir1, dir2), common.mustNotMutateObjectDeep({ recursive: true }));
fs.mkdir(pathname, common.mustNotMutateObjectDeep({ recursive: true }), common.mustCall(function(err, path) {
assert.strictEqual(err, null);
assert.strictEqual(fs.existsSync(pathname), true);
@ -311,8 +311,8 @@ if (common.isMainThread && (common.isLinux || common.isOSX)) {
{
const dir1 = nextdir();
const dir2 = nextdir();
const firstPathCreated = path.join(tmpdir.path, dir1);
const pathname = path.join(tmpdir.path, dir1, dir2);
const firstPathCreated = tmpdir.resolve(dir1);
const pathname = tmpdir.resolve(dir1, dir2);
const p = fs.mkdirSync(pathname, common.mustNotMutateObjectDeep({ recursive: true }));
assert.strictEqual(fs.existsSync(pathname), true);
assert.strictEqual(fs.statSync(pathname).isDirectory(), true);
@ -323,8 +323,8 @@ if (common.isMainThread && (common.isLinux || common.isOSX)) {
{
const dir1 = nextdir();
const dir2 = nextdir();
const pathname = path.join(tmpdir.path, dir1, dir2);
fs.mkdirSync(path.join(tmpdir.path, dir1), common.mustNotMutateObjectDeep({ recursive: true }));
const pathname = tmpdir.resolve(dir1, dir2);
fs.mkdirSync(tmpdir.resolve(dir1), common.mustNotMutateObjectDeep({ recursive: true }));
const p = fs.mkdirSync(pathname, common.mustNotMutateObjectDeep({ recursive: true }));
assert.strictEqual(fs.existsSync(pathname), true);
assert.strictEqual(fs.statSync(pathname).isDirectory(), true);
@ -335,8 +335,8 @@ if (common.isMainThread && (common.isLinux || common.isOSX)) {
{
const dir1 = nextdir();
const dir2 = nextdir();
const pathname = path.join(tmpdir.path, dir1, dir2);
fs.mkdirSync(path.join(tmpdir.path, dir1, dir2), common.mustNotMutateObjectDeep({ recursive: true }));
const pathname = tmpdir.resolve(dir1, dir2);
fs.mkdirSync(tmpdir.resolve(dir1, dir2), common.mustNotMutateObjectDeep({ recursive: true }));
const p = fs.mkdirSync(pathname, common.mustNotMutateObjectDeep({ recursive: true }));
assert.strictEqual(fs.existsSync(pathname), true);
assert.strictEqual(fs.statSync(pathname).isDirectory(), true);
@ -347,8 +347,8 @@ if (common.isMainThread && (common.isLinux || common.isOSX)) {
{
const dir1 = nextdir();
const dir2 = nextdir();
const firstPathCreated = path.join(tmpdir.path, dir1);
const pathname = path.join(tmpdir.path, dir1, dir2);
const firstPathCreated = tmpdir.resolve(dir1);
const pathname = tmpdir.resolve(dir1, dir2);
async function testCase() {
const p = await fs.promises.mkdir(pathname, common.mustNotMutateObjectDeep({ recursive: true }));
assert.strictEqual(fs.existsSync(pathname), true);

View File

@ -16,26 +16,26 @@ function handler(err, folder) {
// Test with plain string
{
const tmpFolder = fs.mkdtempSync(path.join(tmpdir.path, 'foo.'));
const tmpFolder = fs.mkdtempSync(tmpdir.resolve('foo.'));
assert.strictEqual(path.basename(tmpFolder).length, 'foo.XXXXXX'.length);
assert(fs.existsSync(tmpFolder));
const utf8 = fs.mkdtempSync(path.join(tmpdir.path, '\u0222abc.'));
const utf8 = fs.mkdtempSync(tmpdir.resolve('\u0222abc.'));
assert.strictEqual(Buffer.byteLength(path.basename(utf8)),
Buffer.byteLength('\u0222abc.XXXXXX'));
assert(fs.existsSync(utf8));
fs.mkdtemp(path.join(tmpdir.path, 'bar.'), common.mustCall(handler));
fs.mkdtemp(tmpdir.resolve('bar.'), common.mustCall(handler));
// Same test as above, but making sure that passing an options object doesn't
// affect the way the callback function is handled.
fs.mkdtemp(path.join(tmpdir.path, 'bar.'), {}, common.mustCall(handler));
fs.mkdtemp(tmpdir.resolve('bar.'), {}, common.mustCall(handler));
const warningMsg = 'mkdtemp() templates ending with X are not portable. ' +
'For details see: https://nodejs.org/api/fs.html';
common.expectWarning('Warning', warningMsg);
fs.mkdtemp(path.join(tmpdir.path, 'bar.X'), common.mustCall(handler));
fs.mkdtemp(tmpdir.resolve('bar.X'), common.mustCall(handler));
}
// Test with URL object
@ -62,46 +62,46 @@ function handler(err, folder) {
// Test with Buffer
{
const tmpFolder = fs.mkdtempSync(Buffer.from(path.join(tmpdir.path, 'foo.')));
const tmpFolder = fs.mkdtempSync(Buffer.from(tmpdir.resolve('foo.')));
assert.strictEqual(path.basename(tmpFolder).length, 'foo.XXXXXX'.length);
assert(fs.existsSync(tmpFolder));
const utf8 = fs.mkdtempSync(Buffer.from(path.join(tmpdir.path, '\u0222abc.')));
const utf8 = fs.mkdtempSync(Buffer.from(tmpdir.resolve('\u0222abc.')));
assert.strictEqual(Buffer.byteLength(path.basename(utf8)),
Buffer.byteLength('\u0222abc.XXXXXX'));
assert(fs.existsSync(utf8));
fs.mkdtemp(Buffer.from(path.join(tmpdir.path, 'bar.')), common.mustCall(handler));
fs.mkdtemp(Buffer.from(tmpdir.resolve('bar.')), common.mustCall(handler));
// Same test as above, but making sure that passing an options object doesn't
// affect the way the callback function is handled.
fs.mkdtemp(Buffer.from(path.join(tmpdir.path, 'bar.')), {}, common.mustCall(handler));
fs.mkdtemp(Buffer.from(tmpdir.resolve('bar.')), {}, common.mustCall(handler));
// Warning fires only once
fs.mkdtemp(Buffer.from(path.join(tmpdir.path, 'bar.X')), common.mustCall(handler));
fs.mkdtemp(Buffer.from(tmpdir.resolve('bar.X')), common.mustCall(handler));
}
// Test with Uint8Array
{
const encoder = new TextEncoder();
const tmpFolder = fs.mkdtempSync(encoder.encode(path.join(tmpdir.path, 'foo.')));
const tmpFolder = fs.mkdtempSync(encoder.encode(tmpdir.resolve('foo.')));
assert.strictEqual(path.basename(tmpFolder).length, 'foo.XXXXXX'.length);
assert(fs.existsSync(tmpFolder));
const utf8 = fs.mkdtempSync(encoder.encode(path.join(tmpdir.path, '\u0222abc.')));
const utf8 = fs.mkdtempSync(encoder.encode(tmpdir.resolve('\u0222abc.')));
assert.strictEqual(Buffer.byteLength(path.basename(utf8)),
Buffer.byteLength('\u0222abc.XXXXXX'));
assert(fs.existsSync(utf8));
fs.mkdtemp(encoder.encode(path.join(tmpdir.path, 'bar.')), common.mustCall(handler));
fs.mkdtemp(encoder.encode(tmpdir.resolve('bar.')), common.mustCall(handler));
// Same test as above, but making sure that passing an options object doesn't
// affect the way the callback function is handled.
fs.mkdtemp(encoder.encode(path.join(tmpdir.path, 'bar.')), {}, common.mustCall(handler));
fs.mkdtemp(encoder.encode(tmpdir.resolve('bar.')), {}, common.mustCall(handler));
// Warning fires only once
fs.mkdtemp(encoder.encode(path.join(tmpdir.path, 'bar.X')), common.mustCall(handler));
fs.mkdtemp(encoder.encode(tmpdir.resolve('bar.X')), common.mustCall(handler));
}

View File

@ -3,9 +3,8 @@
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const tmpdir = require('../common/tmpdir');
const tempFile = path.join(tmpdir.path, 'fs-non-number-arguments-throw');
const tempFile = tmpdir.resolve('fs-non-number-arguments-throw');
tmpdir.refresh();
fs.writeFileSync(tempFile, 'abc\ndef');

View File

@ -27,7 +27,6 @@ const fixtures = require('../common/fixtures');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
// 0 if not found in fs.constants
const { O_APPEND = 0,
@ -86,7 +85,7 @@ assert.throws(
if (common.isLinux || common.isOSX) {
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
const file = path.join(tmpdir.path, 'a.js');
const file = tmpdir.resolve('a.js');
fs.copyFileSync(fixtures.path('a.js'), file);
fs.open(file, O_DSYNC, common.mustSucceed((fd) => {
fs.closeSync(fd);

View File

@ -4,7 +4,6 @@
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const mode = common.isWindows ? 0o444 : 0o644;
@ -20,7 +19,7 @@ function test(mode, asString) {
(mode | maskToIgnore).toString(8) : (mode | maskToIgnore);
{
const file = path.join(tmpdir.path, `openSync-${suffix}.txt`);
const file = tmpdir.resolve(`openSync-${suffix}.txt`);
const fd = fs.openSync(file, 'w+', input);
assert.strictEqual(fs.fstatSync(fd).mode & 0o777, mode);
fs.closeSync(fd);
@ -28,7 +27,7 @@ function test(mode, asString) {
}
{
const file = path.join(tmpdir.path, `open-${suffix}.txt`);
const file = tmpdir.resolve(`open-${suffix}.txt`);
fs.open(file, 'w+', input, common.mustSucceed((fd) => {
assert.strictEqual(fs.fstatSync(fd).mode & 0o777, mode);
fs.closeSync(fd);

View File

@ -3,13 +3,12 @@ require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
// O_WRONLY without O_CREAT shall fail with ENOENT
const pathNE = path.join(tmpdir.path, 'file-should-not-exist');
const pathNE = tmpdir.resolve('file-should-not-exist');
assert.throws(
() => fs.openSync(pathNE, fs.constants.O_WRONLY),
(e) => e.code === 'ENOENT'

View File

@ -7,7 +7,6 @@ const common = require('../common');
// Refer: https://github.com/nodejs/node/issues/7655
const fs = require('fs');
const path = require('path');
const options = common.mustNotMutateObjectDeep({});
const tmpdir = require('../common/tmpdir');
@ -20,8 +19,8 @@ fs.readdir(__dirname, options, common.mustSucceed());
fs.readdirSync(__dirname, options);
if (common.canCreateSymLink()) {
const sourceFile = path.resolve(tmpdir.path, 'test-readlink');
const linkFile = path.resolve(tmpdir.path, 'test-readlink-link');
const sourceFile = tmpdir.resolve('test-readlink');
const linkFile = tmpdir.resolve('test-readlink-link');
fs.writeFileSync(sourceFile, '');
fs.symlinkSync(sourceFile, linkFile);
@ -31,13 +30,13 @@ if (common.canCreateSymLink()) {
}
{
const fileName = path.resolve(tmpdir.path, 'writeFile');
const fileName = tmpdir.resolve('writeFile');
fs.writeFileSync(fileName, 'ABCD', options);
fs.writeFile(fileName, 'ABCD', options, common.mustSucceed());
}
{
const fileName = path.resolve(tmpdir.path, 'appendFile');
const fileName = tmpdir.resolve('appendFile');
fs.appendFileSync(fileName, 'ABCD', options);
fs.appendFile(fileName, 'ABCD', options, common.mustSucceed());
}
@ -58,13 +57,13 @@ if (!common.isIBMi) { // IBMi does not support fs.watch()
}
{
const tempFileName = path.resolve(tmpdir.path, 'mkdtemp-');
const tempFileName = tmpdir.resolve('mkdtemp-');
fs.mkdtempSync(tempFileName, options);
fs.mkdtemp(tempFileName, options, common.mustSucceed());
}
{
const fileName = path.resolve(tmpdir.path, 'streams');
const fileName = tmpdir.resolve('streams');
fs.WriteStream(fileName, options).once('open', common.mustCall(() => {
fs.ReadStream(fileName, options).destroy();
})).end();

View File

@ -2,7 +2,6 @@
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const { promisify } = require('util');
const read = promisify(fs.read);
@ -21,7 +20,7 @@ const exists = promisify(fs.exists);
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
{
const filename = path.join(tmpdir.path, 'write-promise.txt');
const filename = tmpdir.resolve('write-promise.txt');
const fd = fs.openSync(filename, 'w');
write(fd, Buffer.from('foobar')).then(common.mustCall((obj) => {
assert.strictEqual(typeof obj.bytesWritten, 'number');

View File

@ -14,7 +14,7 @@ tmpdir.refresh();
let count = 0;
const nextDirPath = (name = 'rm') =>
path.join(tmpdir.path, `${name}-${count++}`);
tmpdir.resolve(`${name}-${count++}`);
const isGitPresent = (() => {
try { execSync('git --version'); return true; } catch { return false; }
@ -128,7 +128,7 @@ function removeAsync(dir) {
// Should fail if target does not exist
fs.rm(
path.join(tmpdir.path, 'noexist.txt'),
tmpdir.resolve('noexist.txt'),
common.mustNotMutateObjectDeep({ recursive: true }),
common.mustCall((err) => {
assert.strictEqual(err.code, 'ENOENT');
@ -136,7 +136,7 @@ function removeAsync(dir) {
);
// Should delete a file
const filePath = path.join(tmpdir.path, 'rm-async-file.txt');
const filePath = tmpdir.resolve('rm-async-file.txt');
fs.writeFileSync(filePath, '');
fs.rm(filePath, common.mustNotMutateObjectDeep({ recursive: true }), common.mustCall((err) => {
try {
@ -148,9 +148,9 @@ function removeAsync(dir) {
}));
// Should delete a valid symlink
const linkTarget = path.join(tmpdir.path, 'link-target-async.txt');
const linkTarget = tmpdir.resolve('link-target-async.txt');
fs.writeFileSync(linkTarget, '');
const validLink = path.join(tmpdir.path, 'valid-link-async');
const validLink = tmpdir.resolve('valid-link-async');
fs.symlinkSync(linkTarget, validLink);
fs.rm(validLink, common.mustNotMutateObjectDeep({ recursive: true }), common.mustCall((err) => {
try {
@ -163,7 +163,7 @@ function removeAsync(dir) {
}));
// Should delete an invalid symlink
const invalidLink = path.join(tmpdir.path, 'invalid-link-async');
const invalidLink = tmpdir.resolve('invalid-link-async');
fs.symlinkSync('definitely-does-not-exist-async', invalidLink);
fs.rm(invalidLink, common.mustNotMutateObjectDeep({ recursive: true }), common.mustCall((err) => {
try {
@ -175,8 +175,8 @@ function removeAsync(dir) {
}));
// Should delete a symlink that is part of a loop
const loopLinkA = path.join(tmpdir.path, 'loop-link-async-a');
const loopLinkB = path.join(tmpdir.path, 'loop-link-async-b');
const loopLinkA = tmpdir.resolve('loop-link-async-a');
const loopLinkB = tmpdir.resolve('loop-link-async-b');
fs.symlinkSync(loopLinkA, loopLinkB);
fs.symlinkSync(loopLinkB, loopLinkA);
fs.rm(loopLinkA, common.mustNotMutateObjectDeep({ recursive: true }), common.mustCall((err) => {
@ -215,7 +215,7 @@ if (isGitPresent) {
// Should fail if target does not exist
assert.throws(() => {
fs.rmSync(path.join(tmpdir.path, 'noexist.txt'), common.mustNotMutateObjectDeep({ recursive: true }));
fs.rmSync(tmpdir.resolve('noexist.txt'), common.mustNotMutateObjectDeep({ recursive: true }));
}, {
code: 'ENOENT',
name: 'Error',
@ -223,7 +223,7 @@ if (isGitPresent) {
});
// Should delete a file
const filePath = path.join(tmpdir.path, 'rm-file.txt');
const filePath = tmpdir.resolve('rm-file.txt');
fs.writeFileSync(filePath, '');
try {
@ -234,9 +234,9 @@ if (isGitPresent) {
}
// Should delete a valid symlink
const linkTarget = path.join(tmpdir.path, 'link-target.txt');
const linkTarget = tmpdir.resolve('link-target.txt');
fs.writeFileSync(linkTarget, '');
const validLink = path.join(tmpdir.path, 'valid-link');
const validLink = tmpdir.resolve('valid-link');
fs.symlinkSync(linkTarget, validLink);
try {
fs.rmSync(validLink);
@ -247,7 +247,7 @@ if (isGitPresent) {
}
// Should delete an invalid symlink
const invalidLink = path.join(tmpdir.path, 'invalid-link');
const invalidLink = tmpdir.resolve('invalid-link');
fs.symlinkSync('definitely-does-not-exist', invalidLink);
try {
fs.rmSync(invalidLink);
@ -257,8 +257,8 @@ if (isGitPresent) {
}
// Should delete a symlink that is part of a loop
const loopLinkA = path.join(tmpdir.path, 'loop-link-a');
const loopLinkB = path.join(tmpdir.path, 'loop-link-b');
const loopLinkA = tmpdir.resolve('loop-link-a');
const loopLinkB = tmpdir.resolve('loop-link-b');
fs.symlinkSync(loopLinkA, loopLinkB);
fs.symlinkSync(loopLinkB, loopLinkA);
try {
@ -317,7 +317,7 @@ if (isGitPresent) {
// Should fail if target does not exist
await assert.rejects(fs.promises.rm(
path.join(tmpdir.path, 'noexist.txt'),
tmpdir.resolve('noexist.txt'),
{ recursive: true }
), {
code: 'ENOENT',
@ -326,10 +326,10 @@ if (isGitPresent) {
});
// Should not fail if target does not exist and force option is true
await fs.promises.rm(path.join(tmpdir.path, 'noexist.txt'), common.mustNotMutateObjectDeep({ force: true }));
await fs.promises.rm(tmpdir.resolve('noexist.txt'), common.mustNotMutateObjectDeep({ force: true }));
// Should delete file
const filePath = path.join(tmpdir.path, 'rm-promises-file.txt');
const filePath = tmpdir.resolve('rm-promises-file.txt');
fs.writeFileSync(filePath, '');
try {
@ -340,9 +340,9 @@ if (isGitPresent) {
}
// Should delete a valid symlink
const linkTarget = path.join(tmpdir.path, 'link-target-prom.txt');
const linkTarget = tmpdir.resolve('link-target-prom.txt');
fs.writeFileSync(linkTarget, '');
const validLink = path.join(tmpdir.path, 'valid-link-prom');
const validLink = tmpdir.resolve('valid-link-prom');
fs.symlinkSync(linkTarget, validLink);
try {
await fs.promises.rm(validLink);
@ -353,7 +353,7 @@ if (isGitPresent) {
}
// Should delete an invalid symlink
const invalidLink = path.join(tmpdir.path, 'invalid-link-prom');
const invalidLink = tmpdir.resolve('invalid-link-prom');
fs.symlinkSync('definitely-does-not-exist-prom', invalidLink);
try {
await fs.promises.rm(invalidLink);
@ -363,8 +363,8 @@ if (isGitPresent) {
}
// Should delete a symlink that is part of a loop
const loopLinkA = path.join(tmpdir.path, 'loop-link-prom-a');
const loopLinkB = path.join(tmpdir.path, 'loop-link-prom-b');
const loopLinkA = tmpdir.resolve('loop-link-prom-a');
const loopLinkB = tmpdir.resolve('loop-link-prom-b');
fs.symlinkSync(loopLinkA, loopLinkB);
fs.symlinkSync(loopLinkB, loopLinkA);
try {
@ -402,7 +402,7 @@ if (isGitPresent) {
{
const dir = nextDirPath();
makeNonEmptyDirectory(4, 10, 2, dir, true);
const filePath = (path.join(tmpdir.path, 'rm-args-file.txt'));
const filePath = (tmpdir.resolve('rm-args-file.txt'));
fs.writeFileSync(filePath, '');
const defaults = {

View File

@ -3,7 +3,6 @@ const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
tmpdir.refresh();
@ -16,7 +15,7 @@ tmpdir.refresh();
'DEP0147'
);
assert.throws(
() => fs.rmdirSync(path.join(tmpdir.path, 'noexist.txt'),
() => fs.rmdirSync(tmpdir.resolve('noexist.txt'),
{ recursive: true }),
{ code: 'ENOENT' }
);

View File

@ -3,7 +3,6 @@ const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
tmpdir.refresh();
@ -14,7 +13,7 @@ tmpdir.refresh();
'will be removed. Use fs.rm(path, { recursive: true }) instead',
'DEP0147'
);
const filePath = path.join(tmpdir.path, 'rmdir-recursive.txt');
const filePath = tmpdir.resolve('rmdir-recursive.txt');
fs.writeFileSync(filePath, '');
assert.throws(
() => fs.rmdirSync(filePath, { recursive: true }),

View File

@ -3,14 +3,13 @@ const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
tmpdir.refresh();
{
assert.throws(
() =>
fs.rmdirSync(path.join(tmpdir.path, 'noexist.txt'), { recursive: true }),
fs.rmdirSync(tmpdir.resolve('noexist.txt'), { recursive: true }),
{
code: 'ENOENT',
}
@ -18,7 +17,7 @@ tmpdir.refresh();
}
{
fs.rmdir(
path.join(tmpdir.path, 'noexist.txt'),
tmpdir.resolve('noexist.txt'),
{ recursive: true },
common.mustCall((err) => {
assert.strictEqual(err.code, 'ENOENT');
@ -27,7 +26,7 @@ tmpdir.refresh();
}
{
assert.rejects(
() => fs.promises.rmdir(path.join(tmpdir.path, 'noexist.txt'),
() => fs.promises.rmdir(tmpdir.resolve('noexist.txt'),
{ recursive: true }),
{
code: 'ENOENT',

View File

@ -3,26 +3,25 @@ const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
tmpdir.refresh();
const code = common.isWindows ? 'ENOENT' : 'ENOTDIR';
{
const filePath = path.join(tmpdir.path, 'rmdir-recursive.txt');
const filePath = tmpdir.resolve('rmdir-recursive.txt');
fs.writeFileSync(filePath, '');
assert.throws(() => fs.rmdirSync(filePath, { recursive: true }), { code });
}
{
const filePath = path.join(tmpdir.path, 'rmdir-recursive.txt');
const filePath = tmpdir.resolve('rmdir-recursive.txt');
fs.writeFileSync(filePath, '');
fs.rmdir(filePath, { recursive: true }, common.mustCall((err) => {
assert.strictEqual(err.code, code);
}));
}
{
const filePath = path.join(tmpdir.path, 'rmdir-recursive.txt');
const filePath = tmpdir.resolve('rmdir-recursive.txt');
fs.writeFileSync(filePath, '');
assert.rejects(() => fs.promises.rmdir(filePath, { recursive: true }),
{ code }).then(common.mustCall());

View File

@ -2,7 +2,6 @@
const common = require('../common');
const tmpdir = require('../common/tmpdir');
const fs = require('fs');
const path = require('path');
tmpdir.refresh();
@ -15,7 +14,7 @@ tmpdir.refresh();
'DEP0147'
);
fs.rmdir(
path.join(tmpdir.path, 'noexist.txt'),
tmpdir.resolve('noexist.txt'),
{ recursive: true },
common.mustCall()
);

View File

@ -3,7 +3,6 @@ const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
tmpdir.refresh();
@ -14,7 +13,7 @@ tmpdir.refresh();
'will be removed. Use fs.rm(path, { recursive: true }) instead',
'DEP0147'
);
const filePath = path.join(tmpdir.path, 'rmdir-recursive.txt');
const filePath = tmpdir.resolve('rmdir-recursive.txt');
fs.writeFileSync(filePath, '');
fs.rmdir(filePath, { recursive: true }, common.mustCall((err) => {
assert.strictEqual(err.code, common.isWindows ? 'ENOENT' : 'ENOTDIR');

View File

@ -18,7 +18,7 @@ tmpdir.refresh();
let count = 0;
const nextDirPath = (name = 'rmdir-recursive') =>
path.join(tmpdir.path, `${name}-${count++}`);
tmpdir.resolve(`${name}-${count++}`);
function makeNonEmptyDirectory(depth, files, folders, dirname, createSymLinks) {
fs.mkdirSync(dirname, { recursive: true });

View File

@ -4,7 +4,6 @@ const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const promiseFs = require('fs').promises;
const path = require('path');
const tmpdir = require('../common/tmpdir');
const { isDate } = require('util').types;
const { inspect } = require('util');
@ -14,7 +13,7 @@ tmpdir.refresh();
let testIndex = 0;
function getFilename() {
const filename = path.join(tmpdir.path, `test-file-${++testIndex}`);
const filename = tmpdir.resolve(`test-file-${++testIndex}`);
fs.writeFileSync(filename, 'test');
return filename;
}

View File

@ -4,7 +4,6 @@ import * as common from '../common/index.mjs';
import fs from 'node:fs';
import fsPromises from 'node:fs/promises';
import path from 'node:path';
import assert from 'node:assert';
import tmpdir from '../common/tmpdir.js';
@ -13,7 +12,7 @@ import tmpdir from '../common/tmpdir.js';
const ignoredErrors = new Set(['EINVAL', 'EOVERFLOW']);
tmpdir.refresh();
const filepath = path.resolve(tmpdir.path, 'timestamp');
const filepath = tmpdir.resolve('timestamp');
await (await fsPromises.open(filepath, 'w')).close();

View File

@ -2,7 +2,6 @@
require('../common');
const fixtures = require('../common/fixtures');
const path = require('path');
const fs = require('fs');
const assert = require('assert');
@ -15,7 +14,7 @@ const readStreamOptions = [...streamOpts, 'read'];
const originalFs = { fs };
{
const file = path.join(tmpdir.path, 'write-end-test0.txt');
const file = tmpdir.resolve('write-end-test0.txt');
writeStreamOptions.forEach((fn) => {
const overrideFs = Object.assign({}, originalFs.fs, { [fn]: null });
@ -37,7 +36,7 @@ const originalFs = { fs };
}
{
const file = path.join(tmpdir.path, 'write-end-test0.txt');
const file = tmpdir.resolve('write-end-test0.txt');
const overrideFs = Object.assign({}, originalFs.fs, { writev: 'not a fn' });
const opts = {
fs: overrideFs

View File

@ -27,7 +27,6 @@ if (!common.canCreateSymLink())
const fixtures = require('../common/fixtures');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
@ -35,7 +34,7 @@ tmpdir.refresh();
// Test creating and reading symbolic link
const linkData = fixtures.path('/cycles/root.js');
const linkPath = path.join(tmpdir.path, 'symlink1.js');
const linkPath = tmpdir.resolve('symlink1.js');
let linkTime;
let fileTime;

View File

@ -25,13 +25,12 @@
const common = require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
const linkPath1 = path.join(tmpdir.path, 'junction1');
const linkPath2 = path.join(tmpdir.path, 'junction2');
const linkPath1 = tmpdir.resolve('junction1');
const linkPath2 = tmpdir.resolve('junction2');
const linkTarget = fixtures.fixturesDir;
const linkData = fixtures.fixturesDir;

View File

@ -23,14 +23,13 @@
const common = require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
// Test creating and reading symbolic link
const linkData = fixtures.path('cycles/');
const linkPath = path.join(tmpdir.path, 'cycles_link');
const linkPath = tmpdir.resolve('cycles_link');
tmpdir.refresh();
@ -52,7 +51,7 @@ fs.symlink(linkData, linkPath, 'junction', common.mustSucceed(() => {
// Test invalid symlink
{
const linkData = fixtures.path('/not/exists/dir');
const linkPath = path.join(tmpdir.path, 'invalid_junction_link');
const linkPath = tmpdir.resolve('invalid_junction_link');
fs.symlink(linkData, linkPath, 'junction', common.mustSucceed(() => {
assert(!fs.existsSync(linkPath));

View File

@ -19,11 +19,11 @@ tmpdir.refresh();
const linkTargets = [
'relative-target',
path.join(tmpdir.path, 'absolute-target'),
tmpdir.resolve('absolute-target'),
];
const linkPaths = [
path.relative(process.cwd(), path.join(tmpdir.path, 'relative-path')),
path.join(tmpdir.path, 'absolute-path'),
path.relative(process.cwd(), tmpdir.resolve('relative-path')),
tmpdir.resolve('absolute-path'),
];
function testSync(target, path) {
@ -43,7 +43,7 @@ async function testPromises(target, path) {
}
for (const linkTarget of linkTargets) {
fs.mkdirSync(path.resolve(tmpdir.path, linkTarget));
fs.mkdirSync(tmpdir.resolve(linkTarget));
for (const linkPath of linkPaths) {
testSync(linkTarget, `${linkPath}-${path.basename(linkTarget)}-sync`);
testAsync(linkTarget, `${linkPath}-${path.basename(linkTarget)}-async`);

View File

@ -26,7 +26,6 @@ if (!common.canCreateSymLink())
common.skip('insufficient privileges');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
let linkTime;
@ -37,7 +36,7 @@ tmpdir.refresh();
// Test creating and reading symbolic link
const linkData = fixtures.path('/cycles/root.js');
const linkPath = path.join(tmpdir.path, 'symlink1.js');
const linkPath = tmpdir.resolve('symlink1.js');
fs.symlink(linkData, linkPath, common.mustSucceed(() => {
fs.lstat(linkPath, common.mustSucceed((stats) => {
@ -56,7 +55,7 @@ fs.symlink(linkData, linkPath, common.mustSucceed(() => {
// Test invalid symlink
{
const linkData = fixtures.path('/not/exists/file');
const linkPath = path.join(tmpdir.path, 'symlink2.js');
const linkPath = tmpdir.resolve('symlink2.js');
fs.symlink(linkData, linkPath, common.mustSucceed(() => {
assert(!fs.existsSync(linkPath));

View File

@ -7,7 +7,6 @@ const assert = require('assert');
const { internalBinding } = require('internal/test/binding');
const { UV_DIRENT_UNKNOWN } = internalBinding('constants').fs;
const fs = require('fs');
const path = require('path');
const tmpdir = require('../common/tmpdir');
const filename = 'foo';
@ -15,7 +14,7 @@ const filename = 'foo';
{
// setup
tmpdir.refresh();
fs.writeFileSync(path.join(tmpdir.path, filename), '');
fs.writeFileSync(tmpdir.resolve(filename), '');
}
// getDirents
{

View File

@ -17,10 +17,9 @@ if (common.isIBMi)
const tmpdir = require('../common/tmpdir');
const fs = require('fs');
const path = require('path');
tmpdir.refresh();
const root = path.join(tmpdir.path, 'watched-directory');
const root = tmpdir.resolve('watched-directory');
fs.mkdirSync(root);
const watcher = fs.watch(root, { persistent: false, recursive: false });

View File

@ -23,13 +23,12 @@ if (common.isIBMi)
common.skip('IBMi does not support `fs.watch()`');
const fs = require('fs');
const path = require('path');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
const fn = '新建文夹件.txt';
const a = path.join(tmpdir.path, fn);
const a = tmpdir.resolve(fn);
const watchers = new Set();

View File

@ -11,8 +11,7 @@ if (common.isIBMi)
const assert = require('assert');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
const path = require('path');
const nonexistentFile = path.join(tmpdir.path, 'non-existent');
const nonexistentFile = tmpdir.resolve('non-existent');
const { internalBinding } = require('internal/test/binding');
const {
UV_ENODEV,
@ -48,7 +47,7 @@ tmpdir.refresh();
{
if (common.isOSX || common.isWindows) {
const file = path.join(tmpdir.path, 'file-to-watch');
const file = tmpdir.resolve('file-to-watch');
fs.writeFileSync(file, 'test');
const watcher = fs.watch(file, common.mustNotCall());

View File

@ -32,13 +32,12 @@ const common = require('../common');
// stopped it from getting emitted.
// https://github.com/nodejs/node-v0.x-archive/issues/4027
const path = require('path');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
const filename = path.join(tmpdir.path, 'watched');
const filename = tmpdir.resolve('watched');
fs.writeFileSync(filename, 'quis custodiet ipsos custodes');
fs.watchFile(filename, { interval: 50 }, common.mustCall(function(curr, prev) {

View File

@ -17,7 +17,7 @@ class WatchTestCase {
this.field = field;
this.shouldSkip = !shouldInclude;
}
get dirPath() { return join(tmpdir.path, this.dirName); }
get dirPath() { return tmpdir.resolve(this.dirName); }
get filePath() { return join(this.dirPath, this.fileName); }
}

View File

@ -7,11 +7,10 @@ const common = require('../common');
const assert = require('assert');
const { BigIntStats } = require('internal/fs/utils');
const fs = require('fs');
const path = require('path');
const tmpdir = require('../common/tmpdir');
const enoentFile = path.join(tmpdir.path, 'non-existent-file');
const enoentFile = tmpdir.resolve('non-existent-file');
const expectedStatObject = new BigIntStats(
0n, // dev
0n, // mode

View File

@ -30,7 +30,7 @@ assert.throws(() => {
fs.watchFile(new Object(), common.mustNotCall());
}, { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError' });
const enoentFile = path.join(tmpdir.path, 'non-existent-file');
const enoentFile = tmpdir.resolve('non-existent-file');
const expectedStatObject = new fs.Stats(
0, // dev
0, // mode
@ -85,7 +85,7 @@ watcher.on('stop', common.mustCall());
// Watch events should callback with a filename on supported systems.
// Omitting AIX. It works but not reliably.
if (common.isLinux || common.isOSX || common.isWindows) {
const dir = path.join(tmpdir.path, 'watch');
const dir = tmpdir.resolve('watch');
fs.mkdir(dir, common.mustCall(function(err) {
if (err) assert.fail(err);