mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00

PR-URL: https://github.com/nodejs/node/pull/58836 Fixes: https://github.com/nodejs/node/issues/58826 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
42 lines
1,013 B
JavaScript
42 lines
1,013 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
tmpdir.refresh();
|
|
|
|
const testFilePath = path.join(tmpdir.path, 'fchown-test-file.txt');
|
|
|
|
fs.writeFileSync(testFilePath, 'test content for fchown');
|
|
|
|
{
|
|
const fd = fs.openSync(testFilePath, 'r+');
|
|
const stats = fs.fstatSync(fd);
|
|
const uid = stats.uid;
|
|
const gid = stats.gid;
|
|
|
|
fs.fchown(fd, -1, -1, common.mustSucceed(() => {
|
|
const stats = fs.fstatSync(fd);
|
|
assert.strictEqual(stats.uid, uid);
|
|
assert.strictEqual(stats.gid, gid);
|
|
fs.closeSync(fd);
|
|
}));
|
|
}
|
|
|
|
// Test sync fchown with -1 values
|
|
{
|
|
const fd = fs.openSync(testFilePath, 'r+');
|
|
const stats = fs.fstatSync(fd);
|
|
const uid = stats.uid;
|
|
const gid = stats.gid;
|
|
|
|
fs.fchownSync(fd, -1, -1);
|
|
const statsAfter = fs.fstatSync(fd);
|
|
assert.strictEqual(statsAfter.uid, uid);
|
|
assert.strictEqual(statsAfter.gid, gid);
|
|
|
|
fs.closeSync(fd);
|
|
}
|