Handle the case of a Delete for a reservation stored with just ContainerID without the interface

This commit is contained in:
Michael Cambria 2018-09-20 10:56:07 -04:00
parent 1e8f9525a6
commit a17cadda88

View File

@ -100,6 +100,8 @@ func (s *Store) Release(ip net.IP) error {
// N.B. This function eats errors to be tolerant and // N.B. This function eats errors to be tolerant and
// release as much as possible // release as much as possible
func (s *Store) ReleaseByID(id string, ifname string) error { func (s *Store) ReleaseByID(id string, ifname string) error {
found := false
err := filepath.Walk(s.dataDir, func(path string, info os.FileInfo, err error) error { err := filepath.Walk(s.dataDir, func(path string, info os.FileInfo, err error) error {
if err != nil || info.IsDir() { if err != nil || info.IsDir() {
return nil return nil
@ -112,9 +114,32 @@ func (s *Store) ReleaseByID(id string, ifname string) error {
if err := os.Remove(path); err != nil { if err := os.Remove(path); err != nil {
return nil return nil
} }
found = true
} }
return nil return nil
}) })
if (!found) && (err == nil) {
err = filepath.Walk(s.dataDir, func(path string, info os.FileInfo, err error) error {
if err != nil || info.IsDir() {
return nil
}
data, err := ioutil.ReadFile(path)
if err != nil {
return nil
}
isCurrent := strings.Contains(string(data), "\n")
if !isCurrent {
if strings.TrimSpace(string(data)) == (strings.TrimSpace(id)) {
if err := os.Remove(path); err != nil {
return nil
}
}
}
return nil
})
}
return err return err
} }