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

os: Rename cannot move the file to a different disk drive #13766

Closed
zaz600 opened this issue Dec 29, 2015 · 3 comments
Closed

os: Rename cannot move the file to a different disk drive #13766

zaz600 opened this issue Dec 29, 2015 · 3 comments

Comments

@zaz600
Copy link

@zaz600 zaz600 commented Dec 29, 2015

go version go1.5.2 windows/386

After 92c5736 with MoveFileEx os.Rename("r:\1.txt", "z:\1.txt") on windows generate error:

The system cannot move the file to a different disk drive

https://msdn.microsoft.com/ru-ru/library/windows/desktop/aa365240(v=vs.85).aspx

When moving a file, the destination can be on a different file system or volume. If the destination is on another drive, you must set the MOVEFILE_COPY_ALLOWED flag in dwFlags.

So, syscall_windows.go Rename must be

func Rename(oldpath, newpath string) error {
    from, err := syscall.UTF16PtrFromString(oldpath)
    if err != nil {
        return err
    }
    to, err := syscall.UTF16PtrFromString(newpath)
    if err != nil {
        return err
    }
    return MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING|MOVEFILE_COPY_ALLOWED)
}
zaz600 referenced this issue Dec 29, 2015
Rename now uses MoveFileEx which was previously not available to
use because it is not supported on Windows 2000.

Change-Id: I583d029c4467c9be6d1574a790c423559b441e87
Reviewed-on: https://go-review.googlesource.com/6140
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
@mikioh mikioh added the OS-Windows label Dec 29, 2015
@mikioh mikioh changed the title os.Rename windows: The system cannot move the file to a different disk drive os: Rename cannot move the file to a different disk drive Dec 29, 2015
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Dec 30, 2015

os.Rename doesn't move a file to a different drive on Unix either. I don't see a good reason to use MOVEFILE_COPY_ALLOWED; this is rename, not copy. According to the docs MOVEFILE_COPY_ALLOWED can leave you with two copies of the file, which is not desirable.

zaz600 added a commit to zaz600/gotosser that referenced this issue Jan 2, 2016
В связи с тем, что в 1.5.2 os.Rename перестал переносить файлы на другой диск (golang/go#13766), используем копирование/удаление
@edisonrf

This comment has been minimized.

Copy link

@edisonrf edisonrf commented Mar 31, 2016

what's the status of this issue? I met the same error:
The system cannot move the file to a different disk drive

using go1.6 windows/amd64

@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Mar 31, 2016

@edisonrf, the status is "closed". See previous comments before it was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.