-
Notifications
You must be signed in to change notification settings - Fork 5.7k
fix(ext/node): fs.mkdtemp
and fs.mkdtempSync
compatibility
#30602
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
Conversation
e960867
to
44dd3ed
Compare
Putting it to draft to spike on the directory suffix name generation |
fn temp_path_append_suffix(prefix: &str) -> String { | ||
use rand::Rng; | ||
use rand::distributions::Alphanumeric; | ||
use rand::rngs::OsRng; | ||
|
||
let suffix: String = | ||
(0..6).map(|_| OsRng.sample(Alphanumeric) as char).collect(); | ||
format!("{}{}", prefix, suffix) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chose this approach instead of using the tempfile crate because it relies on fastrand, which is not cryptographically secure. Not that it matters that much, but this method aligns more closely with how libuv handles temp file suffixes https://github.com/nodejs/node/blob/591ba692bfe30408e6a67397e7d18bfa1b9c3561/deps/uv/src/win/fs.c#L1267-L1270
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
fn temp_path_append_suffix(prefix: &str) -> String { | ||
use rand::Rng; | ||
use rand::distributions::Alphanumeric; | ||
use rand::rngs::OsRng; | ||
|
||
let suffix: String = | ||
(0..6).map(|_| OsRng.sample(Alphanumeric) as char).collect(); | ||
format!("{}{}", prefix, suffix) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
fs.mkdtemp
andfs.mkdtempSync
now acceptBuffer
andUint8Array
path. The implementation has been moved to Rust, including directory suffix generation and directory creation.These changes allow the following tests to pass: