Skip to content

Commit

Permalink
Merge branch version/0-46-0-RC1 to adopt changes from PR #3502
Browse files Browse the repository at this point in the history
  • Loading branch information
as-builds committed Sep 25, 2024
2 parents dc7855a + 51af785 commit f590cdb
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 18 deletions.
8 changes: 8 additions & 0 deletions pkg/runtime/links_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build linux || darwin
// +build linux darwin

package runtime

func supportsHardLinks(path string) bool {
return true
}
57 changes: 57 additions & 0 deletions pkg/runtime/links_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package runtime

import (
"os"
"path/filepath"

"github.com/ActiveState/cli/internal/fileutils"
"github.com/ActiveState/cli/internal/logging"
"github.com/ActiveState/cli/internal/multilog"
"github.com/ActiveState/cli/internal/smartlink"
)

const linkTarget = "__target__"
const link = "__link__"

func supportsHardLinks(path string) (supported bool) {
defer func() {
if !supported {
logging.Debug("Enforcing deployment via copy, as hardlinks are not supported")
}
}()

target := filepath.Join(path, linkTarget)
err := fileutils.Touch(target)
if err != nil {
multilog.Error("Error touching target: %v", err)
return false
}
defer func() {
err := os.Remove(target)
if err != nil {
multilog.Error("Error removing target: %v", err)
}
}()

lnk := filepath.Join(path, link)
if fileutils.TargetExists(lnk) {
err := os.Remove(lnk)
if err != nil {
multilog.Error("Error removing previous link: %v", err)
return false
}
}

logging.Debug("Attempting to link '%s' to '%s'", lnk, target)
err = smartlink.Link(target, lnk)
if err != nil {
logging.Debug("Test link creation failed: %v", err)
return false
}
err = os.Remove(lnk)
if err != nil {
multilog.Error("Error removing link: %v", err)
}

return true
}
40 changes: 22 additions & 18 deletions pkg/runtime/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ type Opts struct {
type SetOpt func(*Opts)

type setup struct {
path string
opts *Opts
depot *depot
env *envdef.Collection
buildplan *buildplan.BuildPlan
path string
opts *Opts
depot *depot
supportsHardLinks bool
env *envdef.Collection
buildplan *buildplan.BuildPlan

// toBuild encompasses all artifacts that will need to be build for this runtime.
// This does NOT mean every artifact in the runtime closure if this is an update (as oppose to a fresh toInstall).
Expand Down Expand Up @@ -163,16 +164,17 @@ func newSetup(path string, bp *buildplan.BuildPlan, env *envdef.Collection, depo
}

return &setup{
path: path,
opts: opts,
env: env,
depot: depot,
buildplan: bp,
toBuild: artifactsToBuild.ToIDMap(),
toDownload: artifactsToDownload.ToIDMap(),
toUnpack: artifactsToUnpack.ToIDMap(),
toInstall: artifactsToInstall.ToIDMap(),
toUninstall: artifactsToUninstall,
path: path,
opts: opts,
env: env,
depot: depot,
supportsHardLinks: supportsHardLinks(depot.depotPath),
buildplan: bp,
toBuild: artifactsToBuild.ToIDMap(),
toDownload: artifactsToDownload.ToIDMap(),
toUnpack: artifactsToUnpack.ToIDMap(),
toInstall: artifactsToInstall.ToIDMap(),
toUninstall: artifactsToUninstall,
}, nil
}

Expand Down Expand Up @@ -463,12 +465,14 @@ func (s *setup) install(id strfmt.UUID) (rerr error) {
return errs.Wrap(err, "Could not get env")
}

if envDef.NeedsTransforms() {
if envDef.NeedsTransforms() || !s.supportsHardLinks {
if err := s.depot.DeployViaCopy(id, envDef.InstallDir, s.path); err != nil {
return errs.Wrap(err, "Could not deploy artifact via copy")
}
if err := envDef.ApplyFileTransforms(s.path); err != nil {
return errs.Wrap(err, "Could not apply env transforms")
if envDef.NeedsTransforms() {
if err := envDef.ApplyFileTransforms(s.path); err != nil {
return errs.Wrap(err, "Could not apply env transforms")
}
}
} else {
if err := s.depot.DeployViaLink(id, envDef.InstallDir, s.path); err != nil {
Expand Down

0 comments on commit f590cdb

Please sign in to comment.