Beispiel #1
0
func UpdateDirectory(origd string, subs []os.FileInfo, force_reload bool,
	sdir *store.Directory) error {
	old_itms := make(map[string]*store.Item, len(sdir.Items))
	for _, itm := range sdir.Items {
		old_itms[*itm.Name] = itm
	}
	imgs, vids, dirs := filterEntries(subs)
	sdir.SubDirectories = dirs

	new_items := make([]*store.Item, 0, len(imgs)+len(vids))

	for _, new_vid := range vids {
		old_vid, _ := old_itms[*new_vid.Name]
		new_items = append(new_items, mergeVideo(old_vid, new_vid))
	}

	for _, new_img := range imgs {
		old_img, ok := old_itms[*new_img.Name]
		if !ok || old_img.FileTimestamp == nil ||
			*old_img.FileTimestamp != *new_img.FileTimestamp || force_reload {
			err := LoadImageFile(path.Join(origd, *new_img.Name), new_img)
			if err != nil {
				log.Printf("%s: %s\n", path.Join(origd, *new_img.Name), err.Error())
			}
		}
		new_items = append(new_items, mergeImage(old_img, new_img))
		if len(new_img.Keywords) == 0 {
			log.Printf("%s: no keywords\n", path.Join(origd, *new_img.Name))
		}
	}

	sdir.Items = new_items
	return nil
}
Beispiel #2
0
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
}
Beispiel #3
0
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
}