signManifest 和 generateManifest
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user