Fix removing existing sqlite files
continuous-integration/drone/push Build is failing Details

This commit is contained in:
kolaente 2020-06-27 16:34:53 +02:00
parent 974d028e51
commit e17cac854a
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 9 additions and 2 deletions

View File

@ -168,12 +168,19 @@ func initSqliteEngine() (engine *xorm.Engine, err error) {
}
// Try opening the db file to return a better error message if that does not work
var exists = true
if _, err := os.Stat(path); err != nil {
exists = !os.IsNotExist(err)
}
file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0)
if err != nil {
return nil, fmt.Errorf("could not open database file [uid=%d, gid=%d]: %s", os.Getuid(), os.Getgid(), err)
}
_ = file.Close() // We directly close the file because we only want to check if it is writable. It will be reopened lazily later by xorm.
_ = os.Remove(path) // Remove the file to not prevent the db from creating another one
_ = file.Close() // We directly close the file because we only want to check if it is writable. It will be reopened lazily later by xorm.
if !exists {
_ = os.Remove(path) // Remove the file to not prevent the db from creating another one
}
return xorm.NewEngine("sqlite3", path)
}