mirror of
https://github.com/gtsteffaniak/filebrowser.git
synced 2026-11-24 23:49:41 -05:00
26 lines
658 B
Go
26 lines
658 B
Go
package sqlitebusy
|
|
|
|
import (
|
|
"errors"
|
|
|
|
sqlite "modernc.org/sqlite"
|
|
sqlite3 "modernc.org/sqlite/lib"
|
|
)
|
|
|
|
// isBusyOrLocked reports whether err is a SQLITE_BUSY or SQLITE_LOCKED error
|
|
// from the pure-Go (modernc.org/sqlite) driver. The driver enables extended
|
|
// result codes, so Error.Code() may carry extra detail in the high bits (e.g.
|
|
// SQLITE_BUSY_SNAPSHOT); only the lowest byte holds the primary code.
|
|
func isBusyOrLocked(err error) bool {
|
|
var sqliteErr *sqlite.Error
|
|
if !errors.As(err, &sqliteErr) {
|
|
return false
|
|
}
|
|
switch sqliteErr.Code() & 0xff {
|
|
case sqlite3.SQLITE_BUSY, sqlite3.SQLITE_LOCKED:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|