[agent-operator]-无聊的更新内容
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// DownloadFile 下载一个文件,调用http.Get()下载
|
||||
func DownloadFile(downloadUrl, desFile string) (downloadOk bool, resultLog []string) {
|
||||
|
||||
log.InfoF("Downloading file: %s", downloadUrl)
|
||||
|
||||
@@ -5,11 +5,12 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// AppendSourceToFile 将源文件的内容添加到目标文件,使用golang标准库完成,跨平台、安全性更强
|
||||
func AppendSourceToFile(sourceFile, targetFile string) bool {
|
||||
// AppendFileToFile 将源文件的内容添加到目标文件
|
||||
func AppendFileToFile(sourceFile, targetFile string) bool {
|
||||
|
||||
// 打开源文件
|
||||
source, err := os.Open(sourceFile)
|
||||
@@ -68,6 +69,7 @@ func AppendContentToFile(content string, targetFile string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// AppendOverwriteListContentToFile 将一个字符串列表中的内容,一行一行的写入文件中
|
||||
func AppendOverwriteListContentToFile(contentList []string, targetFile string) bool {
|
||||
|
||||
err := os.Remove(targetFile)
|
||||
@@ -95,8 +97,8 @@ func AppendOverwriteListContentToFile(contentList []string, targetFile string) b
|
||||
return true
|
||||
}
|
||||
|
||||
// AppendContentWithSplitLineToFile 专门为k8s的yaml文件设计的,在每次写入内容之前,先写入一行分隔符
|
||||
func AppendContentWithSplitLineToFile(content string, targetFile string) bool {
|
||||
// AppendK8sYamlWithSplitLineToFile 专门为k8s的yaml文件设计的,在每次写入内容之前,先写入一行分隔符
|
||||
func AppendK8sYamlWithSplitLineToFile(content string, targetFile string) bool {
|
||||
|
||||
// 打开文件用于追加。如果文件不存在,将会创建一个新文件。
|
||||
file, err := os.OpenFile(targetFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
@@ -119,13 +121,13 @@ func AppendContentWithSplitLineToFile(content string, targetFile string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// AppendNullToFile 清空一个文件
|
||||
func AppendNullToFile(targetFile string) bool {
|
||||
// AppendNullOverWriteToFile 清空一个文件
|
||||
func AppendNullOverWriteToFile(targetFile string) bool {
|
||||
|
||||
// 使用os.O_TRUNC清空文件内容
|
||||
file, err := os.OpenFile(targetFile, os.O_TRUNC|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
log.ErrorF("[AppendNullToFile] - Error opening file: %s, error is %s", targetFile, err.Error())
|
||||
log.ErrorF("[AppendNullOverWriteToFile] - Error opening file: %s, error is %s", targetFile, err.Error())
|
||||
return false
|
||||
}
|
||||
defer file.Close() // 确保在函数退出前关闭文件
|
||||
@@ -270,8 +272,8 @@ func ReadAllContentFromFile(fileFullPath string) (result []string) {
|
||||
return result
|
||||
}
|
||||
|
||||
// FolderMoveFiles 将源文件夹中除了子文件夹外的所有文件移动到目标文件夹
|
||||
func FolderMoveFiles(srcDir, dstDir string) error {
|
||||
// MoveFolerToAnother 将源文件夹中除了子文件夹外的所有文件移动到目标文件夹
|
||||
func MoveFolerToAnother(srcDir, dstDir string) error {
|
||||
// 读取源文件夹中的所有条目
|
||||
entries, err := os.ReadDir(srcDir)
|
||||
if err != nil {
|
||||
@@ -297,3 +299,14 @@ func FolderMoveFiles(srcDir, dstDir string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetCurrentUserFolder 获取运行环境当前用户的根目录
|
||||
func GetCurrentUserFolder() string {
|
||||
usr, err := user.Current()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return ""
|
||||
}
|
||||
|
||||
return usr.HomeDir
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user