2024-04-01 17:02:29 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"os/exec"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Info struct {
|
|
|
|
Cache struct {
|
|
|
|
Stats struct {
|
|
|
|
Total_chunks float64
|
|
|
|
Total_csize float64
|
|
|
|
Total_size float64
|
|
|
|
Total_unique_chunks float64
|
|
|
|
Unique_csize float64
|
|
|
|
Unique_size float64
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Repository struct {
|
|
|
|
Last_modified string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (info *Info) LastmodUnix() float64 {
|
|
|
|
lastmod, err := time.Parse("2006-01-02T15:04:05.999999", info.Repository.Last_modified)
|
|
|
|
if err != nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
return float64(lastmod.Unix())
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetInfo(path string) (*Info, error) {
|
|
|
|
cmd := exec.Command("borg", "info", "--json", path)
|
|
|
|
cmd.Env = append(cmd.Env, "BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes")
|
2024-04-03 08:13:42 +02:00
|
|
|
cmd.Env = append(cmd.Env, "BORG_RELOCATED_REPO_ACCESS_IS_OK=yes")
|
2024-04-01 17:02:29 +02:00
|
|
|
|
|
|
|
stdout, err := cmd.Output()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
data := &Info{}
|
|
|
|
err = json.Unmarshal([]byte(stdout), data)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return data, nil
|
|
|
|
}
|