Skip to content

Commit

Permalink
fix, Lock Symflower installations to make sure two evalatuions do not…
Browse files Browse the repository at this point in the history
… install at the same time
  • Loading branch information
zimmski committed Apr 19, 2024
1 parent 9d7b756 commit 41a4590
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/rivo/uniseg v0.4.7 // indirect
github.com/schollz/progressbar/v3 v3.14.2 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/symflower/lockfile v0.0.0-20240419143922-aa3b60940c84 // indirect
github.com/termie/go-shutil v0.0.0-20140729215957-bcacb06fecae // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/yuin/goldmark v1.7.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
github.com/nightlyone/lockfile v1.0.0 h1:RHep2cFKK4PonZJDdEl4GmkabuhbsRMgk/k3uAmxBiA=
github.com/nightlyone/lockfile v1.0.0/go.mod h1:rywoIealpdNse2r832aiD9jRk8ErCatROs6LzC841CI=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -25,6 +27,8 @@ github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/symflower/lockfile v0.0.0-20240419143922-aa3b60940c84 h1:yhPz6r3LLBDjoV0rIDUlyuvWQg9L4MTfdksLVX6/q0s=
github.com/symflower/lockfile v0.0.0-20240419143922-aa3b60940c84/go.mod h1:W/87GmsQmvlsvcXeuAlTGjIpTHrTTHDEIVH936LjnqI=
github.com/termie/go-shutil v0.0.0-20140729215957-bcacb06fecae h1:vgGSvdW5Lqg+I1aZOlG32uyE6xHpLdKhZzcTEktz5wM=
github.com/termie/go-shutil v0.0.0-20140729215957-bcacb06fecae/go.mod h1:quDq6Se6jlGwiIKia/itDZxqC5rj6/8OdFyMMAwTxCs=
github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
Expand Down
31 changes: 26 additions & 5 deletions tools/symflower.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import (
"runtime"
"strconv"
"strings"
"time"

pkgerrors "github.com/pkg/errors"
"github.com/symflower/eval-dev-quality/util"
"github.com/symflower/lockfile"
"github.com/zimmski/osutil"

"github.com/symflower/eval-dev-quality/util"
)

// SymflowerVersion holds the version of Symflower required for this revision of the evaluation.
Expand All @@ -27,6 +30,28 @@ func SymflowerInstall(log *log.Logger, installPath string) (err error) {
return pkgerrors.WithStack(err)
}

if err := os.MkdirAll(installPath, 0755); err != nil {
return pkgerrors.WithStack(err)
}

lock, err := lockfile.New(filepath.Join(installPath, "install.lock"))
if err != nil {
return pkgerrors.WithStack(err)
}
for {
if err := lock.TryLock(); err == nil {
break
}

log.Printf("Try to lock %s for installing but need to wait for another process", installPath)
time.Sleep(time.Second)
}
defer func() {
if e := lock.Unlock(); e != nil {
err = errors.Join(err, e)
}
}()

// Check if install path is already used for binaries, or add it if not.
installPathUsed := false
for _, p := range strings.Split(os.Getenv(osutil.EnvironmentPathIdentifier), string(os.PathListSeparator)) {
Expand Down Expand Up @@ -96,10 +121,6 @@ func SymflowerInstall(log *log.Logger, installPath string) (err error) {
return pkgerrors.WithStack(pkgerrors.WithMessage(err, fmt.Sprintf("unkown architecture %s", a)))
}

if err := os.MkdirAll(installPath, 0755); err != nil {
return pkgerrors.WithStack(err)
}

log.Printf("Install \"symflower\" to %s", symflowerInstallPath)
if err := osutil.DownloadFileWithProgress("https://download.symflower.com/local/v"+SymflowerVersion+"/symflower-"+osIdentifier+"-"+architectureIdentifier, symflowerInstallPath); err != nil {
return pkgerrors.WithStack(pkgerrors.WithMessage(err, fmt.Sprintf("cannot download to %s", symflowerInstallPath)))
Expand Down

0 comments on commit 41a4590

Please sign in to comment.