Skip to content

Commit

Permalink
fix: Improve performance of stripExif command with concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
Hayao0819 committed Jan 21, 2025
1 parent fc3ecfe commit f59a9d0
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions tools/cmd/stripexif/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"os"
"path"
"path/filepath"
"sync"

"github.com/Hayao0819/hayao0819.com/tools/utils/cobrautil"
"github.com/Hayao0819/nahi/flist"
"github.com/Hayao0819/nahi/futils"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -37,14 +39,30 @@ func Cmd() *cobra.Command {
}

errs := []error{}

wg := sync.WaitGroup{}
wg.Add(len(*files))

for _, file := range *files {
err := stripExif(file)
if err != nil {
cmd.PrintErrln(err)
errs = append(errs, err)
}
go func() {
if futils.IsDir(file) {
wg.Done()
return
}

cmd.PrintErrln("strip exif from", file)
err := stripExif(file)
if err != nil {
cmd.PrintErrln(err)
errs = append(errs, err)
}

wg.Done()
}()
}

wg.Wait()

if len(errs) > 0 {
return errors.New("error occurred. see logs")
}
Expand Down

0 comments on commit f59a9d0

Please sign in to comment.