Skip to content

Commit

Permalink
fix: Adding folder when created and fixing panic on close
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Mar 8, 2023
1 parent b2c121f commit 660d84a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
20 changes: 16 additions & 4 deletions pkg/crud/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ func (a App) start(ctx context.Context) {
directories = append(directories, item)
} else {
a.notify(ctx, provider.NewStartEvent(item))
a.sanitizeOrphan(ctx, directories, item)

if created := a.sanitizeOrphan(ctx, directories, item); !created.IsZero() {
directories = append(directories, created)
}
}

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

func (a App) sanitizeOrphan(ctx context.Context, directories Items, item absto.Item) {
func (a App) sanitizeOrphan(ctx context.Context, directories Items, item absto.Item) absto.Item {
dirname := item.Dir()

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

if !a.sanitizeOnStart {
logger.Warn("File with name `%s` doesn't have a parent directory", item.Pathname)
return
return absto.Item{}
}

logger.Info("Creating folder `%s`", dirname)

if err := a.storageApp.CreateDir(ctx, dirname); err != nil {
logger.Error("create a parent directory for `%s`: %s", item.Pathname, err)
return absto.Item{}
}

item, err := a.storageApp.Info(ctx, dirname)
if err != nil {
logger.Error("getting the parent directory infos `%s`: %s", item.Pathname, err)
return absto.Item{}
}

return item
}

func (a App) rename(ctx context.Context, item absto.Item, name string) absto.Item {
Expand Down
7 changes: 7 additions & 0 deletions pkg/provider/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,13 @@ func (e EventBus) Done() <-chan struct{} {
}

func (e EventBus) Push(event Event) error {
select {
case <-e.closed:
e.increaseMetric(event, "refused")
return errors.New("bus is closed")
default:
}

select {
case <-e.closed:
e.increaseMetric(event, "refused")
Expand Down

0 comments on commit 660d84a

Please sign in to comment.