-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
fs: special input -1 on chown, lchown and fchown
#58836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nodejs-github-bot
merged 1 commit into
nodejs:main
from
himself65:himself65/2025/06/25/loose
Jun 29, 2025
+126
−9
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -627,27 +627,36 @@ constexpr std::string_view FastStringKey::as_string_view() const { | |
|
|
||
| // Converts a V8 numeric value to a corresponding C++ primitive or enum type. | ||
| template <typename T, | ||
| bool loose = false, | ||
| typename = std::enable_if_t<std::numeric_limits<T>::is_specialized || | ||
| std::is_enum_v<T>>> | ||
| T FromV8Value(v8::Local<v8::Value> value) { | ||
| if constexpr (std::is_enum_v<T>) { | ||
| using Underlying = std::underlying_type_t<T>; | ||
| return static_cast<T>(FromV8Value<Underlying>(value)); | ||
| return static_cast<T>(FromV8Value<Underlying, loose>(value)); | ||
| } else if constexpr (std::is_integral_v<T> && std::is_unsigned_v<T>) { | ||
| static_assert( | ||
| std::numeric_limits<T>::max() <= std::numeric_limits<uint32_t>::max() && | ||
| std::numeric_limits<T>::min() >= | ||
| std::numeric_limits<uint32_t>::min(), | ||
| "Type is out of unsigned integer range"); | ||
| CHECK(value->IsUint32()); | ||
| if constexpr (!loose) { | ||
| CHECK(value->IsUint32()); | ||
| } else { | ||
| CHECK(value->IsNumber()); | ||
| } | ||
| return static_cast<T>(value.As<v8::Uint32>()->Value()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty sure that at least according to the V8 API contract, |
||
| } else if constexpr (std::is_integral_v<T> && std::is_signed_v<T>) { | ||
| static_assert( | ||
| std::numeric_limits<T>::max() <= std::numeric_limits<int32_t>::max() && | ||
| std::numeric_limits<T>::min() >= | ||
| std::numeric_limits<int32_t>::min(), | ||
| "Type is out of signed integer range"); | ||
| CHECK(value->IsInt32()); | ||
| if constexpr (!loose) { | ||
| CHECK(value->IsInt32()); | ||
| } else { | ||
| CHECK(value->IsNumber()); | ||
| } | ||
| return static_cast<T>(value.As<v8::Int32>()->Value()); | ||
| } else { | ||
| static_assert(std::is_floating_point_v<T>, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| '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 testFile = path.join(tmpdir.path, 'chown-test-file.txt'); | ||
|
|
||
| fs.writeFileSync(testFile, 'test content for chown'); | ||
|
|
||
| const stats = fs.statSync(testFile); | ||
| const uid = stats.uid; | ||
| const gid = stats.gid; | ||
|
|
||
| // -1 for uid and gid means "don't change the value" | ||
| { | ||
himself65 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fs.chown(testFile, -1, -1, common.mustSucceed(() => { | ||
| const stats = fs.statSync(testFile); | ||
| assert.strictEqual(stats.uid, uid); | ||
| assert.strictEqual(stats.gid, gid); | ||
| })); | ||
| } | ||
| { | ||
| fs.chownSync(testFile, -1, -1); | ||
| const stats = fs.statSync(testFile); | ||
| assert.strictEqual(stats.uid, uid); | ||
| assert.strictEqual(stats.gid, gid); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| '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); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| '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 testFile = path.join(tmpdir.path, 'lchown-test-file.txt'); | ||
| const testLink = path.join(tmpdir.path, 'lchown-test-link'); | ||
|
|
||
| fs.writeFileSync(testFile, 'test content for lchown'); | ||
| fs.symlinkSync(testFile, testLink); | ||
|
|
||
| const stats = fs.lstatSync(testLink); | ||
| const uid = stats.uid; | ||
| const gid = stats.gid; | ||
|
|
||
| // -1 for uid and gid means "don't change the value" | ||
| { | ||
| fs.lchown(testLink, -1, -1, common.mustSucceed(() => { | ||
| const stats = fs.lstatSync(testLink); | ||
| assert.strictEqual(stats.uid, uid); | ||
| assert.strictEqual(stats.gid, gid); | ||
| })); | ||
| } | ||
| { | ||
| fs.lchownSync(testLink, -1, -1); | ||
| const stats = fs.lstatSync(testLink); | ||
| assert.strictEqual(stats.uid, uid); | ||
| assert.strictEqual(stats.gid, gid); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.