-
-
Couldn't load subscription status.
- Fork 33.6k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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>, | ||
|
|
||
| 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); | ||
| } | ||
| 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); | ||
| } |
| 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); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.