|
| 1 | +// Flags: --experimental-vfs |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +constcommon=require('../common'); |
| 5 | +constassert=require('assert'); |
| 6 | +constfs=require('fs'); |
| 7 | +constfsp=require('fs/promises'); |
| 8 | +constpath=require('path'); |
| 9 | +constvfs=require('node:vfs'); |
| 10 | + |
| 11 | +constmountPoint=path.resolve('/tmp/vfs-lchown-'+process.pid); |
| 12 | +constmyVfs=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 | +functionassertOwnership(filePath,uid,gid){ |
| 22 | +conststats=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 | +awaitnewPromise((resolve,reject)=>{ |
| 34 | +fs.lchown(path.join(mountPoint,'async-link.txt'),234,567,(err)=>{ |
| 35 | +if(err)reject(err); |
| 36 | +elseresolve(); |
| 37 | +}); |
| 38 | +}); |
| 39 | +assertOwnership('/async-target.txt',0,0); |
| 40 | +assertOwnership('/async-link.txt',234,567); |
| 41 | + |
| 42 | +awaitfsp.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