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: install changes mtimes of binaries even when otherwise unchanged #32338

Open
dan-lind opened this issue May 30, 2019 · 4 comments
Open
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. ToolSpeed Unfortunate
Milestone

Comments

@dan-lind
Copy link

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

$ go version
 go1.12.4 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
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ko1dli/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/ko1dli/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/mnt/c/Users/ko1dli/git/serverless-alias-search/src/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-build698955985=/tmp/go-build -gno-record-gcc-switches"

What did you do?

$ ls -ltr ~/go/bin
total 1438344
-rwxrwxrwx 1 ko1dli ko1dli 16718552 May 30 18:38 alias-search
-rwxrwxrwx 1 ko1dli ko1dli 16120748 May 30 18:38 cognito-post-confirmation
-rwxrwxrwx 1 ko1dli ko1dli 22844935 May 30 18:38 create-account-collect
-rwxrwxrwx 1 ko1dli ko1dli 21897771 May 30 18:38 create-account-sign

$ date
Thu May 30 18:39:22 DST 2019

$ go install -x ./...
WORK=/tmp/go-build166854083

$ ls -ltr ~/go/bin
total 1438344
-rwxrwxrwx 1 ko1dli ko1dli 16718552 May 30 18:40 alias-search
-rwxrwxrwx 1 ko1dli ko1dli 16120748 May 30 18:40 cognito-post-confirmation
-rwxrwxrwx 1 ko1dli ko1dli 22844935 May 30 18:40 create-account-collect
-rwxrwxrwx 1 ko1dli ko1dli 21897771 May 30 18:40 create-account-sign

What did you expect to see?

I expected go install leave the installed files alone, since nothing changed.

What did you see instead?

Every file was recreated with a new date (checked with stat). I'm using WSL on Windows 10, not sure if this might affect this behaviour.

@dan-lind dan-lind changed the title go install touches unchanged files go install touches unchanged files May 30, 2019
@dan-lind dan-lind changed the title go install touches unchanged files go install creates new binaries even when unchanged May 30, 2019
@mdempsky mdempsky changed the title go install creates new binaries even when unchanged cmd/go: install replaces binaries even when unchanged May 30, 2019
@mdempsky
Copy link
Member

I expected go install leave the installed files alone, since nothing changed.

Can you elaborate on why you expected this? Alternatively, on what problems this is causing for you?

I'm using WSL on Windows 10, not sure if this might affect this behaviour.

For what it's worth, I see the same behavior on Linux, so I don't think this is Windows-specific. I think this is just working as intended at the moment.

@dan-lind
Copy link
Author

The problem I'm facing is described in this issue here, related to AWS Cloudformation: aws/aws-cli#3131

I guess you can always argue that this is an issue with AWS Cloudformation, but more generally any implementation that considers the create/change date when determining if a binary has been changed or not would have this issue.

@ALTree ALTree added this to the Go1.14 milestone May 31, 2019
@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 31, 2019
@bcmills
Copy link
Contributor

bcmills commented Sep 16, 2019

Compare #33468.
Contrast #31629.

CC @jayconrod

@bcmills bcmills modified the milestones: Go1.14, Unplanned Sep 16, 2019
@bcmills
Copy link
Contributor

bcmills commented Feb 18, 2021

I think this behavior is intentional, but the file shouldn't actually be overwritten if it isn't stale.

// Whether we're smart enough to avoid a complete rebuild
// depends on exactly what the staleness and rebuild algorithms
// are, as well as potentially the state of the Go build cache.
// We don't really want users to be able to infer (or worse start depending on)
// those details from whether the modification time changes during
// "go install", so do a best-effort update of the file times to make it
// look like we rewrote a.Target even if we did not. Updating the mtime
// may also help other mtime-based systems that depend on our
// previous mtime updates that happened more often.
// This is still not perfect - we ignore the error result, and if the file was
// unwritable for some reason then pretending to have written it is also
// confusing - but it's probably better than not doing the mtime update.
//
// But don't do that for the special case where building an executable
// with -linkshared implicitly installs all its dependent libraries.
// We want to hide that awful detail as much as possible, so don't
// advertise it by touching the mtimes (usually the libraries are up
// to date).
if !a.buggyInstall && !b.IsCmdList {
if cfg.BuildN {
b.Showcmd("", "touch %s", a.Target)
} else if err := allowInstall(a); err == nil {
now := time.Now()
os.Chtimes(a.Target, now, now)
}
}

@bcmills bcmills changed the title cmd/go: install replaces binaries even when unchanged cmd/go: install changes mtimes of binaries even when otherwise unchanged Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. ToolSpeed Unfortunate
Projects
None yet
Development

No branches or pull requests

4 participants