Ejemplo n.º 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
}
Ejemplo n.º 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
}