// save writes all snapshots to their designated files.
save writes all snapshots to their designated files.
// save writes all snapshots to their designated files .
func (s snapshots) save() error {
	snapshotsByPath := map[string][]*snapshot{}
	for _, snap := range s {
		_, ok := snapshotsByPath[snap.path]
		if !ok {
			snapshotsByPath[snap.path] = []*snapshot{}
		}
		snapshotsByPath[snap.path] = append(snapshotsByPath[snap.path], snap)
	}
	for path, snaps := range snapshotsByPath {
		if path == "" {
			continue
		}
		snapshotMap := snapshots{}
		for _, snap := range snaps {
			if snap.shouldRemove {
				continue
			}
			snapshotMap[snap.id] = snap
		}
		data, err := encode(snapshotMap)
		if err != nil {
			return err
		}
		err = ioutil.WriteFile(path, data, 0666)
		if err != nil {
			return err
		}
	}
	return nil
}
func ( s snapshots ) save ( ) error { snapshotsByPath := map [ string ] [ ] * snapshot { } for _ , snap := range s { _ , ok := snapshotsByPath [ snap . path ] if ! ok { snapshotsByPath [ snap . path ] = [ ] * snapshot { } } snapshotsByPath [ snap . path ] = append ( snapshotsByPath [ snap . path ] , snap ) } for path , snaps := range snapshotsByPath { if path == " " { continue } snapshotMap := snapshots { } for _ , snap := range snaps { if snap . shouldRemove { continue } snapshotMap [ snap . id ] = snap } data , err := encode ( snapshotMap ) if err != nil { return err } err = ioutil . WriteFile ( path , data , 0666 ) if err != nil { return err } } return nil }
save writes all snapshots to their designated files.
save writes all snapshots to their designated files .