refactor: simplify.
This commit is contained in:
parent
a356fe3980
commit
90dae742e4
@ -104,16 +104,9 @@ func watch(acmeFile string, baseConfig *dumper.BaseConfig) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func manageEvent(watcher *fsnotify.Watcher, event fsnotify.Event, acmeFile string, previousHash []byte, baseConfig *dumper.BaseConfig) ([]byte, error) {
|
func manageEvent(watcher *fsnotify.Watcher, event fsnotify.Event, acmeFile string, previousHash []byte, baseConfig *dumper.BaseConfig) ([]byte, error) {
|
||||||
if event.Op&fsnotify.Rename == fsnotify.Rename {
|
err := manageRename(watcher, event, acmeFile)
|
||||||
err := watcher.Remove(acmeFile)
|
if err != nil {
|
||||||
if err != nil {
|
return nil, err
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = watcher.Add(acmeFile)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hash, err := calculateHash(acmeFile)
|
hash, err := calculateHash(acmeFile)
|
||||||
@ -136,6 +129,22 @@ func manageEvent(watcher *fsnotify.Watcher, event fsnotify.Event, acmeFile strin
|
|||||||
return hash, nil
|
return hash, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func manageRename(watcher *fsnotify.Watcher, event fsnotify.Event, acmeFile string) error {
|
||||||
|
if event.Op&fsnotify.Rename == fsnotify.Rename {
|
||||||
|
err := watcher.Remove(acmeFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = watcher.Add(acmeFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func calculateHash(acmeFile string) ([]byte, error) {
|
func calculateHash(acmeFile string) ([]byte, error) {
|
||||||
file, err := os.Open(acmeFile)
|
file, err := os.Open(acmeFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user