mirror of https://github.com/status-im/consul.git
Merge pull request #3318 from hashicorp/issue_3207
Clean up temporary files on write errors, and ignore any temporary se…
This commit is contained in:
commit
56d651f991
|
@ -5,6 +5,7 @@ FEATURES:
|
|||
IMPROVEMENTS:
|
||||
|
||||
BUG FIXES:
|
||||
* agent: Clean up temporary files during disk write errors when persisting services and checks. [GH-3207]
|
||||
|
||||
## 0.9.0 (July 20, 2017)
|
||||
|
||||
|
|
|
@ -1485,15 +1485,25 @@ func writeFileAtomic(path string, contents []byte) error {
|
|||
return err
|
||||
}
|
||||
if _, err := fh.Write(contents); err != nil {
|
||||
fh.Close()
|
||||
os.Remove(tempPath)
|
||||
return err
|
||||
}
|
||||
if err := fh.Sync(); err != nil {
|
||||
fh.Close()
|
||||
os.Remove(tempPath)
|
||||
return err
|
||||
}
|
||||
if err := fh.Close(); err != nil {
|
||||
fh.Close()
|
||||
os.Remove(tempPath)
|
||||
return err
|
||||
}
|
||||
return os.Rename(tempPath, path)
|
||||
if err := os.Rename(tempPath, path); err != nil {
|
||||
os.Remove(tempPath)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddService is used to add a service entry.
|
||||
|
@ -2072,6 +2082,12 @@ func (a *Agent) loadServices(conf *Config) error {
|
|||
continue
|
||||
}
|
||||
|
||||
// Skip all partially written temporary files
|
||||
if strings.HasSuffix(fi.Name(), "tmp") {
|
||||
a.logger.Printf("[WARN] Ignoring temporary service file %v", fi.Name())
|
||||
continue
|
||||
}
|
||||
|
||||
// Open the file for reading
|
||||
file := filepath.Join(svcDir, fi.Name())
|
||||
fh, err := os.Open(file)
|
||||
|
|
Loading…
Reference in New Issue