Skip to content

Commit

Permalink
feat: Adding sanitize orphans on start
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Mar 7, 2023
1 parent 4206486 commit 14012e5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/ViBiOh/ChatPotte v0.2.29
github.com/ViBiOh/absto v1.3.1
github.com/ViBiOh/absto v1.3.2
github.com/ViBiOh/auth/v2 v2.14.23
github.com/ViBiOh/exas v0.6.0
github.com/ViBiOh/flags v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/ViBiOh/ChatPotte v0.2.29 h1:8cIZDvkTfKOC4bZaQkxyOM47BcXZQR8ykJPl9LsZpMM=
github.com/ViBiOh/ChatPotte v0.2.29/go.mod h1:GXEpgMQkN0R3CHpqVbuMhS8F6U1S/Qb7qQJ2juFqTtc=
github.com/ViBiOh/absto v1.3.1 h1:9UY2fAgd7GD+zFCoOVIbAOKEzLF8veAoBc6mG/tqQsY=
github.com/ViBiOh/absto v1.3.1/go.mod h1:RXbNesRB3Q9BWMxLeT3DXX29bhk5Tqifo2gssPtQVnk=
github.com/ViBiOh/absto v1.3.2 h1:JZ6RJYh9YABO1QHfPcSjb/fEMjqcPcT59kH/jOr22Ys=
github.com/ViBiOh/absto v1.3.2/go.mod h1:RXbNesRB3Q9BWMxLeT3DXX29bhk5Tqifo2gssPtQVnk=
github.com/ViBiOh/auth/v2 v2.14.23 h1:ZeQ2/tsh4Z3Jcu/y9R4X05uyhBUJeUC6UN8XyaKJ2s4=
github.com/ViBiOh/auth/v2 v2.14.23/go.mod h1:pIMuBueO3sknvnvfAFJBOxTjoGWuxke6lp1ZSh6478w=
github.com/ViBiOh/exas v0.6.0 h1:UWQuzesHShBSMkQw7mWAj4NBwL1Hb/fDcgzk/UpacYQ=
Expand Down
16 changes: 12 additions & 4 deletions pkg/crud/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ func (a App) start(ctx context.Context) {
directories = append(directories, item)
} else {
a.notify(ctx, provider.NewStartEvent(item))

a.sanitizeOrphan(directories, item)
a.sanitizeOrphan(ctx, directories, item)
}

return nil
Expand Down Expand Up @@ -178,9 +177,18 @@ func (a App) sanitizeName(ctx context.Context, item absto.Item) absto.Item {
return a.rename(ctx, item, name)
}

func (a App) sanitizeOrphan(directories Items, item absto.Item) {
if _, ok := directories.FindDirectory(item.Dir()); !ok {
func (a App) sanitizeOrphan(ctx context.Context, directories Items, item absto.Item) {
dirname := item.Dir()

_, ok := directories.FindDirectory(dirname)
if ok {
return
}

if !a.sanitizeOnStart {
logger.Warn("File with name `%s` doesn't have a parent directory", item.Pathname)
} else if err := a.storageApp.CreateDir(ctx, dirname); err != nil {
logger.Error("create a parent directory for `%s`: %s", item.Pathname, err)
}
}

Expand Down

0 comments on commit 14012e5

Please sign in to comment.