新增Harbor管理功能和优化文件操作工具
- 在Base.go中添加Harbor安装、启动、停止和卸载子命令 - 实现Harbor本地安装流程,包括配置文件修改和容器检查 - 在Excutor.go中改进命令执行错误处理 - 在FileUtils.go中新增MoveFileToAnother方法,优化文件移动逻辑 - 修复DockerCompose本地安装命令的文件路径和移动方法
This commit is contained in:
@@ -391,6 +391,39 @@ func FindAndDeleteContentInFile(content string, targetFile string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// MoveFileToAnother 将源文件移动到目标文件
|
||||
func MoveFileToAnother(srcFile, dstFile string) error {
|
||||
|
||||
// 如果dstFile是目录,则将srcFile移动到dstFile目录下
|
||||
if IsDirOrFile(dstFile) {
|
||||
dstFile = filepath.Join(dstFile, filepath.Base(srcFile))
|
||||
}
|
||||
|
||||
// 如果目标文件存在,则删除目标文件
|
||||
if FileExists(dstFile) {
|
||||
err := os.Remove(dstFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("删除目标文件失败: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// 如果源文件不存在,则返回错误
|
||||
if !FileExists(srcFile) {
|
||||
return fmt.Errorf("源文件不存在: %s", srcFile)
|
||||
}
|
||||
|
||||
// 如果目标文件夹不存在,则创建目标文件夹
|
||||
if !FileExists(filepath.Dir(dstFile)) {
|
||||
err := os.MkdirAll(filepath.Dir(dstFile), os.ModePerm)
|
||||
if err != nil {
|
||||
return fmt.Errorf("创建目标文件夹失败: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// 移动文件
|
||||
return os.Rename(srcFile, dstFile)
|
||||
}
|
||||
|
||||
// MoveFolerToAnother 将源文件夹的所有文件递归移动到目标文件夹
|
||||
func MoveFolerToAnother(srcDir, dstDir string) error {
|
||||
// 读取源文件夹中的所有条目
|
||||
|
||||
Reference in New Issue
Block a user