51 lines
917 B
Go
51 lines
917 B
Go
|
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")
|
||
|
|
||
|
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
|
||
|
}
|