Skip to content

Commit

Permalink
use filepath
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1te909 committed Feb 22, 2024
1 parent e40dcf6 commit a29709c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
19 changes: 9 additions & 10 deletions agent/agent_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"errors"
"fmt"
"os"
"path"
"path/filepath"
"runtime"
"strconv"
Expand Down Expand Up @@ -201,9 +200,9 @@ func (a *Agent) RunScript(code string, shell string, args []string, timeout int,
if nushellEnableConfig {
nushellArgs = []string{
"--config",
path.Join(nixAgentEtcDir, "nushell", "config.nu"),
filepath.Join(nixAgentEtcDir, "nushell", "config.nu"),
"--env-config",
path.Join(nixAgentEtcDir, "nushell", "env.nu"),
filepath.Join(nixAgentEtcDir, "nushell", "env.nu"),
}
} else {
nushellArgs = []string{"--no-config-file"}
Expand Down Expand Up @@ -606,9 +605,9 @@ func (a *Agent) InstallNushell(force bool) {

if conf.NushellEnableConfig {
// Create 0-byte config files for Nushell
nushellPath := path.Join(nixAgentEtcDir, "nushell")
nushellConfig := path.Join(nushellPath, "config.nu")
nushellEnv := path.Join(nushellPath, "env.nu")
nushellPath := filepath.Join(nixAgentEtcDir, "nushell")
nushellConfig := filepath.Join(nushellPath, "config.nu")
nushellEnv := filepath.Join(nushellPath, "env.nu")
if !trmm.FileExists(nushellPath) {
err := os.MkdirAll(nushellPath, 0755)
if err != nil {
Expand Down Expand Up @@ -721,7 +720,7 @@ func (a *Agent) InstallNushell(force bool) {

if conf.InstallNushellUrl != "" {
// InstallNushellUrl is not compressed.
err = copyFile(path.Join(tmpDir, tmpAssetName), a.NuBin)
err = copyFile(filepath.Join(tmpDir, tmpAssetName), a.NuBin)
if err != nil {
a.Logger.Errorln("InstallNushell(): Failed to copy nu file to install dir:", err)
return
Expand All @@ -734,7 +733,7 @@ func (a *Agent) InstallNushell(force bool) {
return
}

err = copyFile(path.Join(tmpDir, targzDirName, "nu"), a.NuBin)
err = copyFile(filepath.Join(tmpDir, targzDirName, "nu"), a.NuBin)
if err != nil {
a.Logger.Errorln("InstallNushell(): Failed to copy nu file to install dir:", err)
return
Expand Down Expand Up @@ -854,7 +853,7 @@ func (a *Agent) InstallDeno(force bool) {

if conf.InstallDenoUrl != "" {
// InstallDenoUrl is not compressed.
err = copyFile(path.Join(tmpDir, tmpAssetName), a.DenoBin)
err = copyFile(filepath.Join(tmpDir, tmpAssetName), a.DenoBin)
if err != nil {
a.Logger.Errorln("InstallDeno(): Failed to copy deno file to install dir:", err)
return
Expand All @@ -867,7 +866,7 @@ func (a *Agent) InstallDeno(force bool) {
return
}

err = copyFile(path.Join(tmpDir, "deno"), a.DenoBin)
err = copyFile(filepath.Join(tmpDir, "deno"), a.DenoBin)
if err != nil {
a.Logger.Errorln("InstallDeno(): Failed to copy deno file to install dir:", err)
return
Expand Down
23 changes: 11 additions & 12 deletions agent/agent_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"strconv"
Expand Down Expand Up @@ -162,9 +161,9 @@ func (a *Agent) RunScript(code string, shell string, args []string, timeout int,
if nushellEnableConfig {
nushellArgs = []string{
"--config",
path.Join(a.ProgramDir, "etc", "nushell", "config.nu"),
filepath.Join(a.ProgramDir, "etc", "nushell", "config.nu"),
"--env-config",
path.Join(a.ProgramDir, "etc", "nushell", "env.nu"),
filepath.Join(a.ProgramDir, "etc", "nushell", "env.nu"),
}
} else {
nushellArgs = []string{"--no-config-file"}
Expand Down Expand Up @@ -914,7 +913,7 @@ func (a *Agent) InstallNushell(force bool) {
}
}

programBinDir := path.Join(a.ProgramDir, "bin")
programBinDir := filepath.Join(a.ProgramDir, "bin")
if !trmm.FileExists(programBinDir) {
err := os.MkdirAll(programBinDir, 0755)
if err != nil {
Expand All @@ -925,9 +924,9 @@ func (a *Agent) InstallNushell(force bool) {

if conf.NushellEnableConfig {
// Create 0-byte config files for Nushell
nushellPath := path.Join(a.ProgramDir, "etc", "nushell")
nushellConfig := path.Join(nushellPath, "config.nu")
nushellEnv := path.Join(nushellPath, "env.nu")
nushellPath := filepath.Join(a.ProgramDir, "etc", "nushell")
nushellConfig := filepath.Join(nushellPath, "config.nu")
nushellEnv := filepath.Join(nushellPath, "env.nu")
if !trmm.FileExists(nushellPath) {
err := os.MkdirAll(nushellPath, 0755)
if err != nil {
Expand Down Expand Up @@ -1030,7 +1029,7 @@ func (a *Agent) InstallNushell(force bool) {

if conf.InstallNushellUrl != "" {
// InstallNushellUrl is not compressed.
err = copyFile(path.Join(tmpDir, tmpAssetName), a.NuBin)
err = copyFile(filepath.Join(tmpDir, tmpAssetName), a.NuBin)
if err != nil {
a.Logger.Errorln("InstallNushell(): Failed to copy nu file to install dir:", err)
return
Expand All @@ -1042,7 +1041,7 @@ func (a *Agent) InstallNushell(force bool) {
return
}

err = copyFile(path.Join(tmpDir, "nu.exe"), a.NuBin)
err = copyFile(filepath.Join(tmpDir, "nu.exe"), a.NuBin)
if err != nil {
a.Logger.Errorln("InstallNushell(): Failed to copy nu.exe file to install dir:", err)
return
Expand Down Expand Up @@ -1071,7 +1070,7 @@ func (a *Agent) InstallDeno(force bool) {
}
}

programBinDir := path.Join(a.ProgramDir, "bin")
programBinDir := filepath.Join(a.ProgramDir, "bin")
if !trmm.FileExists(programBinDir) {
err := os.MkdirAll(programBinDir, 0755)
if err != nil {
Expand Down Expand Up @@ -1145,7 +1144,7 @@ func (a *Agent) InstallDeno(force bool) {

if conf.InstallDenoUrl != "" {
// InstallDenoUrl is not compressed.
err = copyFile(path.Join(tmpDir, tmpAssetName), a.DenoBin)
err = copyFile(filepath.Join(tmpDir, tmpAssetName), a.DenoBin)
if err != nil {
a.Logger.Errorln("InstallDeno(): Failed to copy deno file to install dir:", err)
return
Expand All @@ -1158,7 +1157,7 @@ func (a *Agent) InstallDeno(force bool) {
return
}

err = copyFile(path.Join(tmpDir, "deno.exe"), a.DenoBin)
err = copyFile(filepath.Join(tmpDir, "deno.exe"), a.DenoBin)
if err != nil {
a.Logger.Errorln("InstallDeno(): Failed to copy deno.exe file to install dir:", err)
return
Expand Down
5 changes: 2 additions & 3 deletions agent/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"net"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
goDebug "runtime/debug"
Expand Down Expand Up @@ -315,15 +314,15 @@ func (a *Agent) ExtractTarGz(targz string, destDir string) (extractedDir string,

switch header.Typeflag {
case tar.TypeDir:
if err := os.MkdirAll(path.Join(destDir, header.Name), 0755); err != nil {
if err := os.MkdirAll(filepath.Join(destDir, header.Name), 0755); err != nil {
a.Logger.Errorln("ExtractTarGz(): Mkdir() failed:", err.Error())
return "", err
}
if extractedDir == "" {
extractedDir = header.Name
}
case tar.TypeReg:
outFile, err := os.Create(path.Join(destDir, header.Name))
outFile, err := os.Create(filepath.Join(destDir, header.Name))
if err != nil {
a.Logger.Errorln("ExtractTarGz(): Create() failed:", err.Error())
return "", err
Expand Down

0 comments on commit a29709c

Please sign in to comment.