1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2024-11-22 08:25:38 +00:00

dont use slices

This commit is contained in:
thesayyn 2023-11-01 14:10:04 -07:00 committed by Vincent Batts
parent cc12bd7a0b
commit d843e933df
2 changed files with 12 additions and 12 deletions

View file

@ -5,7 +5,6 @@ import (
"io" "io"
"math" "math"
"os" "os"
"slices"
"strings" "strings"
cli "github.com/urfave/cli/v2" cli "github.com/urfave/cli/v2"
@ -76,13 +75,13 @@ func mutateAction(c *cli.Context) error {
&tidyVisitor, &tidyVisitor,
} }
dropped := []int{} dropped := map[int]bool{}
entries := []mtree.Entry{} entries := []mtree.Entry{}
skip: skip:
for _, entry := range spec.Entries { for _, entry := range spec.Entries {
if entry.Parent != nil {
if entry.Parent != nil && slices.Contains(dropped, entry.Parent.Pos) { if _, ok := dropped[entry.Parent.Pos]; ok {
if entry.Type == mtree.DotDotType { if entry.Type == mtree.DotDotType {
// directory for this .. has been dropped so shall this // directory for this .. has been dropped so shall this
continue continue
@ -91,6 +90,7 @@ skip:
// TODO: i am not sure if this is the correct behavior // TODO: i am not sure if this is the correct behavior
entry.Raw = strings.TrimPrefix(entry.Raw, " ") entry.Raw = strings.TrimPrefix(entry.Raw, " ")
} }
}
for _, visitor := range visitors { for _, visitor := range visitors {
drop, err := visitor.Visit(&entry) drop, err := visitor.Visit(&entry)
@ -99,7 +99,7 @@ skip:
} }
if drop { if drop {
dropped = append(dropped, entry.Pos) dropped[entry.Pos] = true
continue skip continue skip
} }
} }

2
go.mod
View file

@ -1,6 +1,6 @@
module github.com/vbatts/go-mtree module github.com/vbatts/go-mtree
go 1.18 go 1.17
require ( require (
github.com/davecgh/go-spew v1.1.1 github.com/davecgh/go-spew v1.1.1