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

cmd/go: build moveOrCopyFile dst forcely on linux #30837

Open
BlackINT3 opened this Issue Mar 14, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@BlackINT3
Copy link

BlackINT3 commented Mar 14, 2019

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

$ go version
go version go1.12 windows/amd64
go version go1.12 linux/amd64

Does this issue reproduce with the latest release?

yes

What did you do?

When exec "build -o dst_file" on windows casually, i got an error:
go build go-test: build output "dst_file" already exists and is not an object file.
I found dst_file allready exists and is an empty file,but it works on linux in the same case.

After reviewed code related build, I found the code snippet:
b.moveOrCopyFile(a.Target, a1.built, perm, false)
force is false, and moveOrCopyFile rename src to dst on linux, and not check the param force.

What did you expect to see?

It should be the same on different os, I think param force should be retain semantically, eg:

			
if err := os.Chmod(src, mode); err == nil {
+	// Be careful about removing/overwriting dst.
+	// Do not remove/overwrite if dst exists and is a directory
+	// or a non-object file.
+	if fi, err := os.Stat(dst); err == nil {
+		if fi.IsDir() {
+			return fmt.Errorf("build output %q already exists and is a directory", dst)
+		}
+		if !force && fi.Mode().IsRegular() && !isObject(dst) {
+			return fmt.Errorf("build output %q already exists and is not an object file", dst)
+		}
+	}
	if err := os.Rename(src, dst); err == nil {
		if cfg.BuildX {
			b.Showcmd("", "mv %s %s", src, dst)
		}
		return nil
	}
}

Can someone give me some advice?
:) thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.