-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
test: add known issue tests for fs.cp #58883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nodejs-github-bot
merged 2 commits into
nodejs:main
from
jasnell:jasnell/fs-cp-known-issues
Jul 1, 2025
+111
−0
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
// We expect this test to fail because the implementation of fsPromise.cp | ||
// does not properly support the use of Buffer as the source or destination | ||
// argument like fs.cpSync does. | ||
|
||
const common = require('../common'); | ||
const { mkdirSync, promises } = require('fs'); | ||
const { join } = require('path'); | ||
const tmpdir = require('../common/tmpdir'); | ||
|
||
tmpdir.refresh(); | ||
|
||
const tmpA = join(tmpdir.path, 'a'); | ||
const tmpB = join(tmpdir.path, 'b'); | ||
|
||
mkdirSync(tmpA, { recursive: true }); | ||
|
||
promises.cp(Buffer.from(tmpA), Buffer.from(tmpB), { | ||
recursive: true, | ||
}).then(common.mustCall()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
// This test will fail because the the implementation does not properly | ||
// handle the case when the `src` or `dest` is a Buffer and the `filter` | ||
// function is utilized when recursively copying directories. | ||
jasnell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const common = require('../common'); | ||
|
||
const { | ||
cpSync, | ||
mkdirSync, | ||
} = require('fs'); | ||
|
||
const { | ||
join, | ||
} = require('path'); | ||
|
||
const tmpdir = require('../common/tmpdir'); | ||
tmpdir.refresh(); | ||
|
||
const pathA = join(tmpdir.path, 'a'); | ||
const pathAC = join(pathA, 'c'); | ||
const pathB = join(tmpdir.path, 'b'); | ||
mkdirSync(pathAC, { recursive: true }); | ||
|
||
cpSync(Buffer.from(pathA), Buffer.from(pathB), { | ||
recursive: true, | ||
// This should be called multiple times, once for each file/directory, | ||
// but it's only called once in this test because we're expecting this | ||
// to fail. | ||
filter: common.mustCall(() => true, 1), | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
jasnell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const common = require('../common'); | ||
|
||
if (!common.isLinux) { | ||
common.skip('This test is only applicable to Linux'); | ||
} | ||
|
||
const { ok, strictEqual } = require('assert'); | ||
const { join } = require('path'); | ||
const path = require('path'); | ||
const tmpdir = require('../common/tmpdir'); | ||
const { | ||
cpSync, | ||
existsSync, | ||
mkdirSync, | ||
writeFileSync, | ||
readFileSync, | ||
} = require('fs'); | ||
tmpdir.refresh(); | ||
|
||
const tmpdirPath = Buffer.from(join(tmpdir.path, 'a', 'c')); | ||
const sepBuf = Buffer.from(path.sep); | ||
|
||
mkdirSync(tmpdirPath, { recursive: true }); | ||
|
||
// The name is the Shift-JIS encoded version of こんにちは世界, | ||
// or "Hello, World" in Japanese. On Linux systems, this name is | ||
// a valid path name and should be handled correctly by the copy | ||
// operation. However, the implementation of cp makes the assumption | ||
// that the path names are UTF-8 encoded, so while we can create the | ||
// file and check its existence using a Buffer, the recursive cp | ||
// operation will fail because it tries to interpret every file name | ||
// as UTF-8. | ||
const name = Buffer.from([ | ||
0x82, 0xB1, 0x82, 0xF1, 0x82, 0xC9, 0x82, | ||
0xBF, 0x82, 0xCD, 0x90, 0x6C, 0x8C, 0x8E, | ||
]); | ||
const testPath = Buffer.concat([tmpdirPath, sepBuf, name]); | ||
|
||
writeFileSync(testPath, 'test content'); | ||
ok(existsSync(testPath)); | ||
strictEqual(readFileSync(testPath, 'utf8'), 'test content'); | ||
|
||
// The cpSync is expected to fail because the implementation does not | ||
// properly handle non-UTF8 names in the path. | ||
|
||
cpSync(join(tmpdir.path, 'a'), join(tmpdir.path, 'b'), { | ||
recursive: true, | ||
filter: common.mustCall(() => true, 1), | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.