Skip to content

Conversation

Tango992
Copy link
Contributor

@Tango992 Tango992 commented Sep 3, 2025

fs.mkdtemp and fs.mkdtempSync now accept Buffer and Uint8Array path. The implementation has been moved to Rust, including directory suffix generation and directory creation.

These changes allow the following tests to pass:

@Tango992 Tango992 force-pushed the fix-node-fs-mkdtemp branch from e960867 to 44dd3ed Compare September 4, 2025 02:12
@Tango992 Tango992 marked this pull request as draft September 4, 2025 14:07
@Tango992
Copy link
Contributor Author

Tango992 commented Sep 4, 2025

Putting it to draft to spike on the directory suffix name generation

@Tango992 Tango992 marked this pull request as ready for review September 5, 2025 11:42
Comment on lines +632 to +640
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)
}
Copy link
Contributor Author

@Tango992 Tango992 Sep 5, 2025

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment on lines +632 to +640
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)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@dsherret dsherret merged commit e60f5d2 into denoland:main Sep 5, 2025
19 of 23 checks passed
@Tango992 Tango992 deleted the fix-node-fs-mkdtemp branch September 6, 2025 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants