mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-06 16:32:31 +01:00
30 lines
448 B
Go
30 lines
448 B
Go
package internal
|
|
|
|
type cleanuper struct {
|
|
cleanupErr func() error
|
|
cleanup func()
|
|
}
|
|
|
|
func NewCleanupErr(cl func() error) *cleanuper {
|
|
return &cleanuper{cleanupErr: cl}
|
|
}
|
|
|
|
func NewCleanup(cl func()) *cleanuper {
|
|
return &cleanuper{cleanup: cl}
|
|
}
|
|
|
|
func (c *cleanuper) Disarm() {
|
|
c.cleanupErr = nil
|
|
c.cleanup = nil
|
|
}
|
|
|
|
func (c *cleanuper) Cleanup() {
|
|
if c.cleanupErr != nil {
|
|
_ = c.cleanupErr()
|
|
}
|
|
|
|
if c.cleanup != nil {
|
|
c.cleanup()
|
|
}
|
|
}
|
|
|