github.com/anishathalye/periscope@v0.3.5/internal/periscope/finish.go (about) 1 package periscope 2 3 import ( 4 "github.com/anishathalye/periscope/internal/herror" 5 6 "fmt" 7 "os" 8 ) 9 10 type FinishOptions struct { 11 } 12 13 func Finish(options *FinishOptions) herror.Interface { 14 path, herr := dbPath() 15 if herr != nil { 16 return herr 17 } 18 info, err := os.Stat(path) 19 if os.IsNotExist(err) { 20 return nil 21 } 22 if os.IsPermission(err) { 23 return herror.Unlikely(err, fmt.Sprintf("cannot access '%s': permission denied", path), ` 24 Ensure that the cache directory is accessible. 25 `) 26 } 27 if err != nil { 28 return herror.Unlikely(err, fmt.Sprintf("could not stat '%s'", path), ` 29 Ensure that the cache directory is readable. 30 `) 31 } 32 if !info.Mode().IsRegular() { 33 return herror.Unlikely(err, fmt.Sprintf("database is not a regular file: '%s'", path), ` 34 This should not happen under regular circumstances. If you are done using the database, you can safely delete it manually with 'rm -f'. 35 `) 36 } 37 err = os.Remove(path) 38 if err != nil { 39 return herror.Unlikely(err, fmt.Sprintf("cannot delete database file: '%s'", path), ` 40 Ensure that the cache directory is writable or manually delete the database file. 41 `) 42 } 43 fmt.Printf("rm %s\n", path) 44 return nil 45 }