This commit is contained in:
dengqn 2024-08-29 15:17:10 +08:00
parent 45532f51db
commit 7d8a3440b3
3 changed files with 46 additions and 0 deletions

0
go.sum Normal file
View File

View File

@ -35,10 +35,16 @@ func main() {
del()
case "r":
rec()
case "v":
v()
break
}
}
func v() {
storage.All()
}
func h() {
fmt.Println("________________________________________________________")
fmt.Println("[h] print this")

View File

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"log"
"os"
"path"
"strconv"
@ -35,6 +36,45 @@ type Version struct {
Desc string `json:"desc"`
}
func All() (all []FileMeta) {
root, _ := os.UserConfigDir()
appRoot, err := os.Open(path.Join(root, "list-version"))
if err != nil {
fmt.Println("%s", "打开文件失败0"+err.Error())
if errors.Is(err, os.ErrNotExist) {
os.Mkdir(path.Join(root, "list-version"), os.ModePerm)
}
}
defer func() {
if appRoot != nil {
appRoot.Close()
}
}()
sub, _ := appRoot.Readdir(0)
pwd, _ := os.Getwd()
log.Println("pwd:", pwd)
for _, fi := range sub {
var meta FileMeta
fileMeta, err := os.Open(path.Join(root, "list-version", fi.Name(), "meta.json"))
// not saved yet
if errors.Is(err, os.ErrNotExist) {
continue
}
defer fileMeta.Close()
// read meta.json
buf, _ := io.ReadAll(fileMeta)
json.Unmarshal(buf, &meta)
fmt.Printf("[%d] %s\n", len(meta.Versions), meta.AbsolutePath)
}
return all
}
func Extract(fullPath string, version Version) {
root, _ := os.UserConfigDir()
pathHex := util.ToHashHex(fullPath)