From a5a2da36f14700e1a10e3ae6753730c103ceb896 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Fri, 8 May 2020 07:56:14 +0200 Subject: [PATCH] Automatically purge when running index command #234 Signed-off-by: Michael Mayer --- internal/commands/index.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/internal/commands/index.go b/internal/commands/index.go index b0a66048d..7ff5a3fb8 100644 --- a/internal/commands/index.go +++ b/internal/commands/index.go @@ -66,16 +66,30 @@ func indexAction(ctx *cli.Context) error { ind := service.Index() - opt := photoprism.IndexOptions{ + indOpt := photoprism.IndexOptions{ Path: subPath, Rescan: ctx.Bool("all"), Convert: ctx.Bool("convert"), } - files := ind.Start(opt) + indexed := ind.Start(indOpt) + + prg := service.Purge() + + prgOpt := photoprism.PurgeOptions{ + Path: subPath, + Ignore: indexed, + } + + if files, photos, err := prg.Start(prgOpt); err != nil { + log.Error(err) + } else if len(files) > 0 || len(photos) > 0 { + log.Infof("removed %d files and %d photos", len(files), len(photos)) + } + elapsed := time.Since(start) - log.Infof("indexed %d files in %s", len(files), elapsed) + log.Infof("indexed %d files in %s", len(indexed), elapsed) conf.Shutdown()