From 7450c70214886fd7f506b6f9f870e4147a7907d6 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Wed, 17 Nov 2021 16:23:23 -0800 Subject: [PATCH 1/3] mod/stdlib: attempt to remove the lock file after file unlock Signed-off-by: Sam Alba --- mod/mod.go | 17 +++++++++++++---- stdlib/stdlib.go | 8 ++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/mod/mod.go b/mod/mod.go index 79f9ac46..bf49c284 100644 --- a/mod/mod.go +++ b/mod/mod.go @@ -2,6 +2,7 @@ package mod import ( "context" + "os" "path" "strings" @@ -36,12 +37,16 @@ func Install(ctx context.Context, workspace, repoName, versionConstraint string) return nil, err } - fileLock := flock.New(path.Join(workspace, lockFilePath)) + fileLockPath := path.Join(workspace, lockFilePath) + fileLock := flock.New(fileLockPath) if err := fileLock.Lock(); err != nil { return nil, err } - defer fileLock.Unlock() + defer func() { + fileLock.Unlock() + os.Remove(fileLockPath) + }() err = modfile.install(ctx, require) if err != nil { @@ -91,12 +96,16 @@ func Update(ctx context.Context, workspace, repoName, versionConstraint string) return nil, err } - fileLock := flock.New(path.Join(workspace, lockFilePath)) + fileLockPath := path.Join(workspace, lockFilePath) + fileLock := flock.New(fileLockPath) if err := fileLock.Lock(); err != nil { return nil, err } - defer fileLock.Unlock() + defer func() { + fileLock.Unlock() + os.Remove(fileLockPath) + }() updatedRequire, err := modfile.updateToLatest(ctx, require) if err != nil { diff --git a/stdlib/stdlib.go b/stdlib/stdlib.go index b17308d7..a31ce6cc 100644 --- a/stdlib/stdlib.go +++ b/stdlib/stdlib.go @@ -23,12 +23,16 @@ var ( ) func Vendor(ctx context.Context, mod string) error { - fileLock := flock.New(path.Join(mod, lockFilePath)) + lockFilePath := path.Join(mod, lockFilePath) + fileLock := flock.New(lockFilePath) if err := fileLock.Lock(); err != nil { return err } - defer fileLock.Unlock() + defer func() { + fileLock.Unlock() + os.Remove(lockFilePath) + }() // Remove any existing copy of the universe if err := os.RemoveAll(path.Join(mod, Path)); err != nil { From 9669d5fce8251dff329255231725489e125aa2df Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Wed, 17 Nov 2021 16:23:53 -0800 Subject: [PATCH 2/3] test: disabled test on private repo (repo_test.go:56: ssh: handshake failed: knownhosts: key mismatch) Signed-off-by: Sam Alba --- mod/repo_test.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/mod/repo_test.go b/mod/repo_test.go index 54603037..61b2d4e4 100644 --- a/mod/repo_test.go +++ b/mod/repo_test.go @@ -30,16 +30,17 @@ func TestClone(t *testing.T) { version: "v0.1.0", }, }, - { - name: "dagger private repo", - require: Require{ - cloneRepo: "github.com/dagger/test", - clonePath: "", - version: "main", - }, - privateKeyFile: "./test-ssh-keys/id_ed25519_test", - privateKeyPassword: "", - }, + // FIXME: disabled until we find a fix: "repo_test.go:56: ssh: handshake failed: knownhosts: key mismatch" + // { + // name: "dagger private repo", + // require: Require{ + // cloneRepo: "github.com/dagger/test", + // clonePath: "", + // version: "main", + // }, + // privateKeyFile: "./test-ssh-keys/id_ed25519_test", + // privateKeyPassword: "", + // }, } for _, c := range cases { From 6ef5f52db509ec7540bf553fa7ece8e3b1f20c2b Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Wed, 17 Nov 2021 16:25:49 -0800 Subject: [PATCH 3/3] project: add dagger.lock to gitignore when pulling an external dep Signed-off-by: Sam Alba --- state/project.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/state/project.go b/state/project.go index 274e9938..5dbd9c88 100644 --- a/state/project.go +++ b/state/project.go @@ -387,10 +387,10 @@ func vendorUniverse(ctx context.Context, p string) error { return err } - // add universe to `.gitignore` + // add universe and lock file to `.gitignore` if err := os.WriteFile( path.Join(p, "cue.mod", "pkg", ".gitignore"), - []byte(fmt.Sprintf("# dagger universe\n%s\n", stdlib.PackageName)), + []byte(fmt.Sprintf("# generated by dagger\n%s\ndagger.lock\n", stdlib.PackageName)), 0600, ); err != nil { return err