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

Fix windows race condition when writing image with duplicate layers #1921

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/v1/layout/write.go
Expand Up @@ -22,6 +22,8 @@ import (
"io"
"os"
"path/filepath"
"runtime"
"sync"

"github.com/google/go-containerregistry/pkg/logs"
v1 "github.com/google/go-containerregistry/pkg/v1"
Expand All @@ -37,6 +39,8 @@ var layoutFile = `{
"imageLayoutVersion": "1.0.0"
}`

var renameMutex sync.Mutex

// AppendImage writes a v1.Image to the Path and updates
// the index.json to reference it.
func (l Path) AppendImage(img v1.Image, options ...Option) error {
Expand Down Expand Up @@ -259,6 +263,11 @@ func (l Path) writeBlob(hash v1.Hash, size int64, rc io.ReadCloser, renamer func
}

renamePath := l.path("blobs", finalHash.Algorithm, finalHash.Hex)

if runtime.GOOS == "windows" {
renameMutex.Lock()
defer renameMutex.Unlock()
}
return os.Rename(w.Name(), renamePath)
}

Expand Down