func (dir *Directory) ToProto() *store.Directory { sdir := new(store.Directory) if dir.index_time != time.Unix(0, 0) { sdir.DirectoryTimestamp = proto.Int64(TimeToProto(dir.index_time)) } for _, img := range dir.images { sdir.Items = append(sdir.Items, img.ToProto()) } return sdir }
func (db *Database) handleLoad( update_disk bool, force_reload bool, lod *loaderLoad) (*loaderResult, error) { if lod.err != nil { return nil, lod.err } var sdir store.Directory // Ignore missing index, means new directory. readIndex(db.IndexPath(lod.rel_pat), &sdir) origd := db.FullOrigPath(lod.rel_pat) subs, err := ioutil.ReadDir(origd) if err != nil { return nil, err } if sdir.DirectoryTimestamp == nil || ProtoToTime(*sdir.DirectoryTimestamp).Before(lod.orgd_mtime) || force_reload { err = UpdateDirectory(origd, subs, force_reload, &sdir) if err == nil { orgd_ts := TimeToProto(lod.orgd_mtime) sdir.DirectoryTimestamp = &orgd_ts if update_disk { err = writeIndex(db.IndexPath(lod.rel_pat), db.IndexTextPath(lod.rel_pat), &sdir) if err != nil { log.Printf("%s: %s\n", lod.rel_pat, err.Error()) err = nil } } } } if err != nil { return nil, err } dir := ProtoToDirectory(&sdir, lod.rel_pat) return &loaderResult{dir: dir, rel_pat: lod.rel_pat, orgd_subs: subs}, nil }