Skip to content
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

Async file copying on windows #8649

Merged
merged 12 commits into from
Feb 4, 2024
Merged

Async file copying on windows #8649

merged 12 commits into from
Feb 4, 2024

Conversation

gvilums
Copy link
Contributor

@gvilums gvilums commented Feb 2, 2024

What does this PR do?

This PR implements fs.promises.cp on windows, and fixes some errors with symlinks with fs.cpSync.

How did you verify your code works?

Tests in cp.test.ts

@gvilums gvilums requested a review from paperdave February 2, 2024 22:00
Copy link
Member

@paperdave paperdave left a comment

Choose a reason for hiding this comment

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

legendary

i have some really minor change requests

src/bun.js/node/node_fs.zig Outdated Show resolved Hide resolved
else
0;
if (windows.CreateSymbolicLinkW(dest, wbuf[0..len :0], flags) == 0) {
if (Maybe(Return.CopyFile).errnoSysP(0, .copyfile, this.osPathIntoSyncErrorBuf(dest))) |e| {
Copy link
Member

Choose a reason for hiding this comment

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

i think you can pass the rc of the api call into this function, instead of 0. it will return null on success. this will eliminate the "should be unreachable" thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

passing rc or 0 doesn't make a difference because rc is known to be zero. The main issue is that constructing the error object may fail, for example if we detect that the status code is actually a success.

I've gone ahead and changed these to instead construct errors with a generic ENOENT code, so that if these do ever get hit the error is at least somewhat helpful.

src/bun.js/node/node_fs.zig Outdated Show resolved Hide resolved
@@ -623,6 +623,15 @@ pub fn normalizeStringGeneric(
) []u8 {
return normalizeStringGenericT(u8, path_, buf, allow_above_root, separator, isSeparator, preserve_trailing_slash);
}

fn separatorAdapter(comptime T: type, func: anytype) fn (T) bool {
Copy link
Member

Choose a reason for hiding this comment

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

this is fine but later this would be legendary to make into a generic wrapper for

"wrap any function with type"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I agree, could probably live in the bun namespace. Only problem is that zig doesn't support variadics, so it can't be fully generalized 🥲

Copy link
Collaborator

Choose a reason for hiding this comment

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

see std.meta.ArgsTuple

it’s like variadics but worse

return struct {
allow_above_root: bool = false,
separator: T = std.fs.path.sep,
isSeparator: fn (T) bool = makeIsSepAnyT(T),
Copy link
Member

Choose a reason for hiding this comment

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

i wish this could be a comptime field but i suspect it isnt so shrimple to do so is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

which field do you think should be comptime?

Copy link
Member

Choose a reason for hiding this comment

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

isSeparator. if i remember correctly it was previously a comptime function. i might be misremembering. what is significant is that i am less certain this function will be inlined. in the previous code (if im right and it used comptime function), then it is almost certain that LLVM inlined a function for this == thing

Copy link
Contributor Author

@gvilums gvilums Feb 3, 2024

Choose a reason for hiding this comment

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

because the entire struct is only ever used in a comptime context I think this should be basically equivalent to passing a comptime parameter (correct me if I'm wrong on that one)

src/sys.zig Show resolved Hide resolved
src/sys.zig Show resolved Hide resolved
src/sys.zig Outdated Show resolved Hide resolved
src/sys.zig Show resolved Hide resolved
src/windows.zig Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented Feb 2, 2024

Copy link
Contributor

github-actions bot commented Feb 2, 2024

Copy link
Contributor

github-actions bot commented Feb 2, 2024

Copy link
Contributor

github-actions bot commented Feb 2, 2024

Copy link
Contributor

github-actions bot commented Feb 3, 2024

❌🪟 @gvilums, there are 11 test regressions on Windows x86_64

  • test\bundler\cli.test.ts
  • test\bundler\esbuild\loader.test.ts
  • test\cli\run\transpiler-cache.test.ts
  • test\js\bun\console\console-iterator.test.ts
  • test\js\bun\util\bun-file-windows.test.ts
  • test\js\node\async_hooks\AsyncLocalStorage.test.ts
  • test\js\node\http\node-http.test.ts
  • test\js\node\module\node-module-module.test.js
  • test\js\node\process\process-args.test.js
  • test\regression\issue\08095.test.ts
  • test\transpiler\template-literal.test.ts

Full Test Output

@Jarred-Sumner Jarred-Sumner merged commit 1a695f1 into main Feb 4, 2024
26 of 31 checks passed
@Jarred-Sumner Jarred-Sumner deleted the georgijs/cpwin branch February 4, 2024 06:33
@Jarred-Sumner
Copy link
Collaborator

awesome

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.

3 participants