signManifest 和 generateManifest

This commit is contained in:
2025-12-07 16:25:37 +08:00
parent bb17b2e476
commit a7022c4c3f
4 changed files with 178 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package file
import (
"fmt"
"io/fs"
"os"
"path/filepath"
"sync"
@@ -131,3 +132,19 @@ func ReadTempFile(subDir, fileName string) ([]byte, error) {
}
return data, nil
}
// WalkTempDir 遍历指定的临时子目录。
// 它会自动处理根路径的拼接,并调用标准库的 filepath.WalkDir。
// subDir: 要遍历的子目录。
// fn: 应用于每个文件和目录的回调函数。
func WalkTempDir(subDir string, fn fs.WalkDirFunc) error {
root := filepath.Join(instance.tempRoot, subDir)
return filepath.WalkDir(root, fn)
}
// GetRelativePathInTemp 将一个在临时目录中的绝对路径,转换为相对于指定的子目录的相对路径。
// 例如absolutePath="C:\tmp\ota\123\lib\a.py", subDir="ota/123" -> 返回 "lib\a.py"
func GetRelativePathInTemp(absolutePath string, subDir string) (string, error) {
basePath := filepath.Join(instance.tempRoot, subDir)
return filepath.Rel(basePath, absolutePath)
}