From 1dcfa6c9afe94e2539d4c2821e24ea9e4cd2a69b Mon Sep 17 00:00:00 2001 From: Dmytro Manchynskyi Date: Sun, 29 May 2022 16:43:30 +0300 Subject: [PATCH] Better error handling --- main.go | 6 ++++++ source_dir.go | 3 +++ source_zip.go | 3 +++ world_optimizer.go | 6 ++---- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 1ba5d91..7aa05a2 100644 --- a/main.go +++ b/main.go @@ -110,6 +110,9 @@ func process(source Source, recursive bool) { func findZipFiles(fs afero.Fs) ([]string, error) { var files []string err := afero.Walk(fs, "", func(path string, f os.FileInfo, err error) error { + if err != nil { + return err + } if strings.HasSuffix(path, ".zip") { files = append(files, path) } @@ -121,6 +124,9 @@ func findZipFiles(fs afero.Fs) ([]string, error) { func findWorldDirs(fs afero.Fs) ([]string, error) { var files []string err := afero.Walk(fs, "", func(path string, f os.FileInfo, err error) error { + if err != nil { + return err + } if filepath.Base(path) == "region" && f.IsDir() { files = append(files, filepath.Dir(path)) } diff --git a/source_dir.go b/source_dir.go index 9759759..8acac38 100644 --- a/source_dir.go +++ b/source_dir.go @@ -54,6 +54,9 @@ func (s *DirSource) Save() error { } err = afero.Walk(s.overlay, "", func(path string, info fs.FileInfo, err error) error { + if err != nil { + return err + } if s.overlay.IsRemoved(path) != nil { return nil } diff --git a/source_zip.go b/source_zip.go index 13ba46e..b00f051 100644 --- a/source_zip.go +++ b/source_zip.go @@ -58,6 +58,9 @@ func (s *ZipSource) Save() error { } zw := kpzip.NewWriter(outFile) err = afero.Walk(s.overlay, "", func(path string, info fs.FileInfo, err error) error { + if err != nil { + return err + } if s.overlay.IsRemoved(path) != nil { return nil } diff --git a/world_optimizer.go b/world_optimizer.go index f412af0..33a72c0 100644 --- a/world_optimizer.go +++ b/world_optimizer.go @@ -7,10 +7,11 @@ import ( "path/filepath" "strings" + "mc-world-trimmer/chunk" + "github.com/Tnze/go-mc/save/region" "github.com/dustin/go-humanize" "github.com/spf13/afero" - "mc-world-trimmer/chunk" ) type WorldOptimizer struct { @@ -215,9 +216,6 @@ func (o *WorldOptimizer) optimizeChunks(dir string) error { continue } - if *verbose { - //o.log(dir, file.Name(), "unchanged", humanize.Bytes(uint64(file.Size()))) - } newWorldSize += uint64(file.Size()) }