Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions integration/autoupdate/tools/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ var (

func TestMain(m *testing.M) {
modules.SetInsecureTestMode(true)
modules.SetModules(&modules.TestModules{TestBuildType: modules.BuildCommunity})
ctx := context.Background()
tmp, err := os.MkdirTemp(os.TempDir(), testBinaryName)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions integration/autoupdate/tools/updater/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ func (p *TestModules) BuildType() string {
return "CLI"
}

// IsEnterpriseBuild returns false for [TestModules].
// IsEnterpriseBuild returns true if `UPDATER_TEST_BUILD` env is set `ent` for [TestModules].
func (p *TestModules) IsEnterpriseBuild() bool {
return os.Getenv(TestBuild) == modules.BuildEnterprise
}

// IsOSSBuild returns false for [TestModules].
// IsOSSBuild returns true if `UPDATER_TEST_BUILD` env is set `oss` for [TestModules].
func (p *TestModules) IsOSSBuild() bool {
return os.Getenv(TestBuild) == modules.BuildOSS
}
Expand Down
2 changes: 2 additions & 0 deletions integration/autoupdate/tools/updater_tsh_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !windows

/*
* Teleport
* Copyright (C) 2024 Gravitational, Inc.
Expand Down
6 changes: 5 additions & 1 deletion lib/utils/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,15 +422,19 @@ func RecursiveChown(dir string, uid, gid int) error {
return nil
}

func CopyFile(src, dest string, perm os.FileMode) error {
func CopyFile(src, dest string, perm os.FileMode) (err error) {
srcFile, err := os.Open(src)
if err != nil {
return trace.ConvertSystemError(err)
}
defer srcFile.Close()
destFile, err := os.OpenFile(dest, os.O_RDWR|os.O_CREATE|os.O_TRUNC, perm)
if err != nil {
return trace.ConvertSystemError(err)
}
defer func() {
err = trace.NewAggregate(err, trace.Wrap(destFile.Close()))
}()
_, err = destFile.ReadFrom(srcFile)
if err != nil {
return trace.ConvertSystemError(err)
Expand Down
10 changes: 4 additions & 6 deletions lib/utils/packaging/unarchive.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,10 @@ func replaceZip(toolsDir string, archivePath string, extractDir string, execName
return trace.Wrap(err)
}
appPath := filepath.Join(toolsDir, baseName)
if err := os.Remove(appPath); err != nil && !os.IsNotExist(err) {
return trace.Wrap(err)
}
// For the Windows build we have to copy binary to be able
// to do this without administrative access as it required
// for symlinks.
// For the Windows build, we need to copy the binary to perform updates without requiring
// administrative access, which would otherwise be needed for creating symlinks.
// Since symlinks are not used on the Windows platform, there's no need to remove appPath
// before copying the new binary — it will simply be replaced.
if err := utils.CopyFile(dest, appPath, 0o755); err != nil {
return trace.Wrap(err)
}
Expand Down