]> Cypherpunks repositories - gostls13.git/commit
cmd/go: remove some fsyncs when writing files
authorMichael Matloob <matloob@golang.org>
Fri, 11 Dec 2020 22:03:17 +0000 (17:03 -0500)
committerMichael Matloob <matloob@golang.org>
Thu, 11 Mar 2021 20:01:00 +0000 (20:01 +0000)
commit4dd9c7cadcbe689ef607931ed839456509e59104
treec970dff270b7f5bb667e0ec09b174fe75274b21b
parent43d5f213e22029039f234edd1ac72c4ff9dd5ae9
cmd/go: remove some fsyncs when writing files

cache.Trim, dowloadZip, rewriteVersionList, writeDiskCache all use
renameio.WriteFile to write their respective files to disk. For the
uses in cache.Trim and downloadZip, instead do of renameio.WriteFile,
do a truncate to the length of the file, then write the relevant bytes
so that a corrupt file (which would contain null bytes because of
the truncate) could be detected. For rewriteVersionList, use
lockedfile.Transform to do the write (which does a truncate as part of
the write too. writeDiskCache stays the same in this CL.

Also desete renameio methods that aren't used and remove the
renameio.WriteFile wrapper and just use renameio.WriteToFile which it
wraps.

There is a possibility of corrupt files in the cache (which was true
even before this CL) so later CLs will add facilities to clear corrupt
files in the cache.

Change-Id: I0d0bda40095e4cb898314315bf313e71650d8d25
Reviewed-on: https://go-review.googlesource.com/c/go/+/277412
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
src/cmd/go/internal/cache/cache.go
src/cmd/go/internal/modfetch/cache.go
src/cmd/go/internal/modfetch/fetch.go
src/cmd/go/internal/renameio/renameio.go
src/cmd/go/internal/renameio/renameio_test.go