MCPcopy
hub / github.com/tailscale/golink / restoreLastSnapshot

Function restoreLastSnapshot

golink.go:964–990  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

962}
963
964func restoreLastSnapshot() error {
965 bs := bufio.NewScanner(bytes.NewReader(LastSnapshot))
966 var restored int
967 for bs.Scan() {
968 link := new(Link)
969 if err := json.Unmarshal(bs.Bytes(), link); err != nil {
970 return err
971 }
972 if link.Short == "" {
973 continue
974 }
975 _, err := db.Load(link.Short)
976 if err == nil {
977 continue // exists
978 } else if !errors.Is(err, fs.ErrNotExist) {
979 return err
980 }
981 if err := db.Save(link); err != nil {
982 return err
983 }
984 restored++
985 }
986 if restored > 0 && *verbose {
987 log.Printf("Restored %v links.", restored)
988 }
989 return bs.Err()
990}
991
992func resolveLink(link *url.URL) (*url.URL, error) {
993 path := link.Path

Callers 1

RunFunction · 0.85

Calls 2

LoadMethod · 0.80
SaveMethod · 0.80

Tested by

no test coverage detected