|
| 1 | +// Flags: --experimental-vfs |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +const common = require('../common'); |
| 5 | +const assert = require('assert'); |
| 6 | +const fs = require('fs'); |
| 7 | +const fsp = require('fs/promises'); |
| 8 | +const path = require('path'); |
| 9 | +const vfs = require('node:vfs'); |
| 10 | + |
| 11 | +const mountPoint = path.resolve('/tmp/vfs-lchown-' + process.pid); |
| 12 | +const myVfs = vfs.create(); |
| 13 | +myVfs.writeFileSync('/sync-target.txt', 'target'); |
| 14 | +myVfs.symlinkSync('/sync-target.txt', '/sync-link.txt'); |
| 15 | +myVfs.writeFileSync('/async-target.txt', 'target'); |
| 16 | +myVfs.symlinkSync('/async-target.txt', '/async-link.txt'); |
| 17 | +myVfs.writeFileSync('/promise-target.txt', 'target'); |
| 18 | +myVfs.symlinkSync('/promise-target.txt', '/promise-link.txt'); |
| 19 | +myVfs.mount(mountPoint); |
| 20 | + |
| 21 | +function assertOwnership(filePath, uid, gid) { |
| 22 | + const stats = fs.lstatSync(path.join(mountPoint, filePath)); |
| 23 | + assert.strictEqual(stats.uid, uid); |
| 24 | + assert.strictEqual(stats.gid, gid); |
| 25 | +} |
| 26 | + |
| 27 | +(async () => { |
| 28 | + try { |
| 29 | + fs.lchownSync(path.join(mountPoint, 'sync-link.txt'), 123, 456); |
| 30 | + assertOwnership('/sync-target.txt', 0, 0); |
| 31 | + assertOwnership('/sync-link.txt', 123, 456); |
| 32 | + |
| 33 | + await new Promise((resolve, reject) => { |
| 34 | + fs.lchown(path.join(mountPoint, 'async-link.txt'), 234, 567, (err) => { |
| 35 | + if (err) reject(err); |
| 36 | + else resolve(); |
| 37 | + }); |
| 38 | + }); |
| 39 | + assertOwnership('/async-target.txt', 0, 0); |
| 40 | + assertOwnership('/async-link.txt', 234, 567); |
| 41 | + |
| 42 | + await fsp.lchown(path.join(mountPoint, 'promise-link.txt'), 345, 678); |
| 43 | + assertOwnership('/promise-target.txt', 0, 0); |
| 44 | + assertOwnership('/promise-link.txt', 345, 678); |
| 45 | + } finally { |
| 46 | + myVfs.unmount(); |
| 47 | + } |
| 48 | +})().then(common.mustCall()); |
0 commit comments