-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add known_issues test for fs.copyFile()
On macOS, fs.copyFile() may not respect file permissions. There is a PR for libuv that should fix this, but until it lands and we can either float a patch or upgrade libuv, have a known_issues test. Ref: #26936 Ref: libuv/libuv#2233 PR-URL: #26939 Refs: #26936 Refs: libuv/libuv#2233 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
- Loading branch information
1 parent
d22b913
commit 583dc5f
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,50 @@ | ||
'use strict'; | ||
|
||
// Test that fs.copyFile() respects file permissions. | ||
// Ref: https://github.com/nodejs/node/issues/26936 | ||
|
||
const common = require('../common'); | ||
|
||
const tmpdir = require('../common/tmpdir'); | ||
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}`); | ||
fs.writeFileSync(source, 'source'); | ||
fs.writeFileSync(dest, 'dest'); | ||
fs.chmodSync(dest, '444'); | ||
|
||
const check = (err) => { | ||
assert.strictEqual(err.code, 'EACCESS'); | ||
assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'dest'); | ||
}; | ||
|
||
return { source, dest, check }; | ||
} | ||
|
||
// Test synchronous API. | ||
{ | ||
const { source, dest, check } = beforeEach(); | ||
assert.throws(() => { fs.copyFileSync(source, dest); }, check); | ||
} | ||
|
||
// Test promises API. | ||
{ | ||
const { source, dest, check } = beforeEach(); | ||
assert.throws(async () => { await fs.promises.copyFile(source, dest); }, | ||
check); | ||
} | ||
|
||
// Test callback API. | ||
{ | ||
const { source, dest, check } = beforeEach(); | ||
fs.copyFile(source, dest, common.mustCall(check)); | ||
} |