GeezerVison is showing github.com — permission: disable FileHandle utimes with permission model · nodejs/node@cf85d54
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/fs/promises.js +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1154,6 +1154,9 @@ async function utimes(path, atime, mtime) { |
1154 | 1154 | } |
1155 | 1155 |
|
1156 | 1156 | async function futimes(handle, atime, mtime) { |
| 1157 | + if (permission.isEnabled()) { |
| 1158 | + throw new ERR_ACCESS_DENIED('futimes API is disabled when Permission Model is enabled.'); |
| 1159 | + } |
1157 | 1160 | atime = toUnixTimestamp(atime, 'atime'); |
1158 | 1161 | mtime = toUnixTimestamp(mtime, 'mtime'); |
1159 | 1162 | return await PromisePrototypeThen( |
|
Collapse file
Copy file name to clipboard +33Lines changed: 33 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Flags: --permission --allow-fs-read=* |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +const common = require('../common'); |
| 5 | +const { isMainThread } = require('worker_threads'); |
| 6 | + |
| 7 | +if (!isMainThread) { |
| 8 | + common.skip('This test only works on a main thread'); |
| 9 | +} |
| 10 | + |
| 11 | +if (!common.hasCrypto) { |
| 12 | + common.skip('no crypto'); |
| 13 | +} |
| 14 | + |
| 15 | +const assert = require('assert'); |
| 16 | +const { open } = require('fs/promises'); |
| 17 | +const fixtures = require('../common/fixtures'); |
| 18 | + |
| 19 | +const regularFile = fixtures.path('permission', 'deny', 'regular-file.md'); |
| 20 | + |
| 21 | +// FileHandle.utimes() must be blocked when the permission model is enabled, |
| 22 | +// consistent with fs.futimes() / fs.futimesSync(). |
| 23 | +(async () => { |
| 24 | + const fh = await open(regularFile, 'r'); |
| 25 | + try { |
| 26 | + await assert.rejects( |
| 27 | + fh.utimes(Date.now(), Date.now()), |
| 28 | + common.expectsError({ code: 'ERR_ACCESS_DENIED' }), |
| 29 | + ); |
| 30 | + } finally { |
| 31 | + await fh.close(); |
| 32 | + } |
| 33 | +})().then(common.mustCall()); |