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 on Windows fails if the source directory contains any files or folders #48183

Closed
supercom32 opened this issue Sep 3, 2021 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows

Comments

@supercom32
Copy link

supercom32 commented Sep 3, 2021

What version of Go are you using (go version)?

$ go version

go version go1.17 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/administrator/.cache/go-build"
GOENV="/home/administrator/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/administrator/Documents/Workspaces/golang/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/administrator/Documents/Workspaces/golang"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/administrator/Documents/Workspaces/golang/src/rscraper/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2599231979=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I built a binary for Windows that simply does the following:

err := os.Rename("c:/temp/directory1", "c:/temp/directory2")

if err != nil {
   fmt.Print("error:  " + err. Error())
}

Where directory1 is a folder that contains files or folders, and directory2 does not exist yet, and both locations exist under the same parent directory.

What did you expect to see?

When running under Windows 10, using CMD as administrator, I expect to see that directory1 is renamed to directory2.

What did you see instead?

I get returned the error "access is denied". If the source directory is empty (Contains no files or folders) the rename occurs as expected. I verified that no files or folders are being locked. In addition, when running under Linux (using valid linux paths), everything works as expected and the directory is successfuly renamed in all cases.

If I am wrong, and this is expected behaviour (I don't think it is) I'm not sure how to go about renaming a directory that already contains data (Another fs library perhaps?). But if this is a genuine bug, then this is pretty basic as I'm supprised no one has raised an issue for it. (^_^);

@seankhliao seankhliao changed the title os.Rename for Windows fails if the source directory contains any files or folders. os: Rename on Windows fails if the source directory contains any files or folders Sep 3, 2021
@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows labels Sep 3, 2021
@seankhliao
Copy link
Member

Is it possible you're running into the situations described here? https://stackoverflow.com/questions/41365318/access-is-denied-when-renaming-folder

@supercom32
Copy link
Author

supercom32 commented Sep 3, 2021

Is it possible you're running into the situations described here? https://stackoverflow.com/questions/41365318/access-is-denied-when-renaming-folder

Ah, this was a good suggestion but unfortunately it does not resolve my issue for me.

Edit: After more fiddling around with Windows, it seems somehow the issue went away. Perhaps a combination of settings listed here, plus rebooting resolved it. I wish I knew exactly what did the trick, but In any case it's working now. Thanks for the awsome suggestion!

@golang golang locked and limited conversation to collaborators Sep 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

3 participants