Skip to content

Commit

Permalink
Better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
xtrafrancyz committed May 29, 2022
1 parent c36d5b9 commit 1dcfa6c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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))
}
Expand Down
3 changes: 3 additions & 0 deletions source_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions source_zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 2 additions & 4 deletions world_optimizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
}

Expand Down

0 comments on commit 1dcfa6c

Please sign in to comment.