atomicDelete renames the path to a hidden file before removal
(path string)
| 158 | |
| 159 | // atomicDelete renames the path to a hidden file before removal |
| 160 | func atomicDelete(path string) error { |
| 161 | // create a hidden dir for an atomic removal |
| 162 | atomicPath := filepath.Join(filepath.Dir(path), fmt.Sprintf(".%s", filepath.Base(path))) |
| 163 | if err := os.Rename(path, atomicPath); err != nil { |
| 164 | if os.IsNotExist(err) { |
| 165 | return nil |
| 166 | } |
| 167 | return err |
| 168 | } |
| 169 | return os.RemoveAll(atomicPath) |
| 170 | } |