Skip to content

vfs: lchown follows symlinks instead of updating the link #64572

Description

@trivikr

Version

main

Platform

macOS 26.5.2

Subsystem

vfs

What steps will reproduce the bug?

import fs from 'node:fs';
import path from 'node:path';
import vfs from 'node:vfs';

const mountPoint = path.resolve(`/tmp/vfs-lchown-${process.pid}`);

const virtualFs = vfs.create({ emitExperimentalWarning: false });
virtualFs.writeFileSync('/target.txt', 'target');
virtualFs.symlinkSync('/target.txt', '/link.txt');
virtualFs.mount(mountPoint);

fs.lchownSync(path.join(mountPoint, 'link.txt'), 123, 456);

virtualFs.unmount();

const targetStats = virtualFs.lstatSync('/target.txt');
const linkStats = virtualFs.lstatSync('/link.txt');

console.log({
  target: { uid: targetStats.uid, gid: targetStats.gid },
  link: { uid: linkStats.uid, gid: linkStats.gid },
});

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

{
  target: { uid: 0, gid: 0 },
  link: { uid: 123, gid: 456 }
}

lchown should not follow the symlink; it should update the symlink’s own metadata and leave the target unchanged.

What do you see instead?

{
  target: { uid: 123, gid: 456 },
  link: { uid: 0, gid: 0 }
}

fs.lchownSync() updates the symlink target’s uid/gid while the symlink itself remains unchanged.

Additional information

No response

Metadata

Metadata

Assignees

Labels

vfsIssues and PRs related to the virtual filesystem subsystem.

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions