mirror of
https://github.com/containers/podman.git
synced 2025-10-17 19:24:04 +08:00
Improved hooks monitoring
...to work for specific edge cases with a simpler solution. Re-reads hooks directories after any changes are detected by the watchers. Added monitoring test for adding a different invalid hook to primary directory. Some issues with prior code: - ReadDir would stop when it encounters an invalid hook, rather than registering an error but continuing to read the valid hook. - Wouldn’t account for Rename and Chmod events. - After doing a mv of the hooks file instead of rm, it would still think the hooks file is in the directory, but it has been moved to another location. - If a hook file was renamed, it would register the renamed file as a separate hook and not delete the original, so it would then execute the hook twice - once for the renamed file, and once for the original name which it did not delete. Signed-off-by: samc24 <sam.chaturvedi24@gmail.com>
This commit is contained in:

committed by
Sameer Chaturvedi

parent
7c9095ea1d
commit
d6ea4b4139
@ -4,7 +4,6 @@ package hooks
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -138,26 +137,3 @@ func (m *Manager) Hooks(config *rspec.Spec, annotations map[string]string, hasBi
|
||||
|
||||
return extensionStageHooks, nil
|
||||
}
|
||||
|
||||
// remove remove a hook by name.
|
||||
func (m *Manager) remove(hook string) (ok bool) {
|
||||
m.lock.Lock()
|
||||
defer m.lock.Unlock()
|
||||
_, ok = m.hooks[hook]
|
||||
if ok {
|
||||
delete(m.hooks, hook)
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
// add adds a hook by path
|
||||
func (m *Manager) add(path string) (err error) {
|
||||
m.lock.Lock()
|
||||
defer m.lock.Unlock()
|
||||
hook, err := Read(path, m.extensionStages)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.hooks[filepath.Base(path)] = hook
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user