cheapcash/rename.go

36 lines
472 B
Go
Raw Normal View History

2021-11-16 13:18:23 +00:00
package cheapcash
import "os"
func (c *Cache) Rename(old, new string) error {
err := checkDir(sanitizePath(c.Path))
if err != nil {
return err
}
checkOld, err := c.Exists(c.Path + old)
if err != nil {
return err
}
checkNew, err := c.Exists(c.Path + new)
if err != nil {
return err
}
if !checkOld {
return ErrNotExists
}
if checkNew {
return ErrExists
}
err = os.Rename(c.Path+old, c.Path+new)
if err != nil {
return err
}
return nil
}