removeFileOnClose will setup the callback to wipe out the file safely when all references to it are closed.
(fref *FileRef)
| 309 | // removeFileOnClose will setup the callback to wipe out the file safely |
| 310 | // when all references to it are closed. |
| 311 | func (s *Store) removeFileOnClose(fref *FileRef) (os.FileInfo, error) { |
| 312 | finfo, err := fref.file.Stat() |
| 313 | if err != nil { |
| 314 | return nil, err |
| 315 | } |
| 316 | |
| 317 | if len(finfo.Name()) > 0 { |
| 318 | fref.OnAfterClose(func() { |
| 319 | fileName := finfo.Name() |
| 320 | go func() { |
| 321 | s.m.Lock() |
| 322 | delete(s.fileRefMap, fileName) |
| 323 | s.m.Unlock() |
| 324 | err := os.Remove(path.Join(s.dir, fileName)) |
| 325 | if err != nil { |
| 326 | if s.options.CollectionOptions.Log != nil { |
| 327 | s.options.CollectionOptions.Log( |
| 328 | "store: error deleting file %s, err: %v", |
| 329 | fileName, err) |
| 330 | } |
| 331 | } |
| 332 | }() |
| 333 | }) |
| 334 | } |
| 335 | |
| 336 | return finfo, nil |
| 337 | } |
| 338 | |
| 339 | // -------------------------------------------------------- |
| 340 |
no test coverage detected