Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disable windows agent update as windows does not support self r… #806

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 13 additions & 8 deletions agent/update/update_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func download(file string) (string, error) {
}

func Update(tar string) error {
return fmt.Errorf("linux support only")
// download
fname, err := download(tar)
if err != nil {
Expand All @@ -57,11 +58,11 @@ func Update(tar string) error {
}
fm, err := os.Stat(ov)
if err != nil {
return err
return fmt.Errorf("stat file %s error: %s", ov, err)
}
fi, err := os.Stat(nv)
if err != nil {
return err
return fmt.Errorf("stat file %s error: %s", nv, err)
}
if fi.Mode().IsDir() {
return fmt.Errorf("%s is directory", nv)
Expand Down Expand Up @@ -105,12 +106,9 @@ func UnTar(dst, src string) (target string, err error) {
// 构建文件解压后的路径
destPath := filepath.Join(dst, file.Name)

// 如果是目录,创建相应的目录
// skip directory
if file.FileInfo().IsDir() {
err := os.MkdirAll(destPath, os.ModePerm)
if err != nil {
return "", err
}
continue
}

// 打开 ZIP 文件中的每个文件
Expand All @@ -120,6 +118,13 @@ func UnTar(dst, src string) (target string, err error) {
}
defer srcFile.Close()

// now create directory for files
err = os.MkdirAll(filepath.Dir(destPath), 0755)
if err != nil {
log.Printf("mdkir:%s, error:%s", filepath.Base(destPath), err)
return "", err
}

// 创建目标文件
dest, err := os.Create(destPath)
if err != nil {
Expand All @@ -132,7 +137,7 @@ func UnTar(dst, src string) (target string, err error) {
if err != nil {
return "", err
}
if strings.HasSuffix(destPath, "categraf") {
if strings.HasSuffix(destPath, "categraf.exe") {
target = destPath
}
}
Expand Down