From e921fe1732aedc5a4657d8d4fc229587ef9e8e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Wed, 4 Sep 2024 22:51:54 +0100 Subject: [PATCH] fix: remove file after completion #59 --- cmd/um/main.go | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/cmd/um/main.go b/cmd/um/main.go index cb48457..11bffdd 100644 --- a/cmd/um/main.go +++ b/cmd/um/main.go @@ -254,7 +254,20 @@ func (p *processor) processFile(filePath string) error { if len(allDec) == 0 { logger.Fatal("skipping while no suitable decoder") } - return p.process(filePath, allDec) + + if err := p.process(filePath, allDec); err != nil { + return err + } + + // if source file need to be removed + if p.removeSource { + err := os.RemoveAll(filePath) + if err != nil { + return err + } + logger.Info("source file removed after success conversion", zap.String("source", filePath)) + } + return nil } func (p *processor) process(inputFile string, allDec []common.NewDecoderFunc) error { @@ -374,16 +387,6 @@ func (p *processor) process(inputFile string, allDec []common.NewDecoderFunc) er } } - // if source file need to be removed - if p.removeSource { - err := os.RemoveAll(inputFile) - if err != nil { - return err - } - logger.Info("successfully converted, and source file is removed", zap.String("source", inputFile), zap.String("destination", outPath)) - } else { - logger.Info("successfully converted", zap.String("source", inputFile), zap.String("destination", outPath)) - } - + logger.Info("successfully converted", zap.String("source", inputFile), zap.String("destination", outPath)) return nil }