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

add windows support #5

Closed
wants to merge 1 commit into from
Closed

add windows support #5

wants to merge 1 commit into from

Conversation

natefinch
Copy link

This replaces the os.Rename call with two separate implementations depending
on target OS. On windows it uses the movefileex syscall to make the move
atomic, unlike the implementation of os.Rename.

Needs tests, for sure.

This replaces the os.Rename call with two separate implementations depending
on target OS.  On windows it uses the movefileex syscall to make the move
atomic, unlike the implementation of os.Rename.
@natefinch
Copy link
Author

Fixes #1

Copy link
Collaborator

@stapelberg stapelberg left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Just two minor comments.

zfile_windows.go Show resolved Hide resolved
func replaceFile(source, destination string) error {
src, err := syscall.UTF16PtrFromString(source)
if err != nil {
return &os.LinkError{"replace", source, destination, err}
Copy link
Collaborator

Choose a reason for hiding this comment

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

here and below: could you please change the literal construction to use field names to be robust when os.LinkError changes? E.g. &os.LinkError{Op: "replace", Old: source, New: destination, Err: err}

Copy link
Author

Choose a reason for hiding this comment

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

Ahh yeah, definitely.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let me know once you pushed the change :)

}

// see http://msdn.microsoft.com/en-us/library/windows/desktop/aa365240(v=vs.85).aspx
if err := moveFileEx(src, dest, movefile_replace_existing|movefile_write_through); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, golang.org/x/sys/windows has a wrapper for MoveFileExW, so it could be used instead of generating one here.

@stapelberg
Copy link
Collaborator

golang/go#32188 (comment) says MoveFileEx is not atomic under windows, and ReplaceFile should instead be used.

@stapelberg
Copy link
Collaborator

golang/go#22397 (comment) says nothing is atomic under windows. Closing this until someone comes up with new evidence.

@stapelberg stapelberg closed this Jul 7, 2019
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