summaryrefslogtreecommitdiff
path: root/vendor/github.com/ncruces/go-sqlite3/backup.go
diff options
context:
space:
mode:
authorLibravatar Terin Stock <terinjokes@gmail.com>2025-03-09 17:47:56 +0100
committerLibravatar Terin Stock <terinjokes@gmail.com>2025-03-10 01:59:49 +0100
commit3ac1ee16f377d31a0fb80c8dae28b6239ac4229e (patch)
treef61faa581feaaeaba2542b9f2b8234a590684413 /vendor/github.com/ncruces/go-sqlite3/backup.go
parent[chore] update URLs to forked source (diff)
downloadgotosocial-3ac1ee16f377d31a0fb80c8dae28b6239ac4229e.tar.xz
[chore] remove vendor
Diffstat (limited to 'vendor/github.com/ncruces/go-sqlite3/backup.go')
-rw-r--r--vendor/github.com/ncruces/go-sqlite3/backup.go134
1 files changed, 0 insertions, 134 deletions
diff --git a/vendor/github.com/ncruces/go-sqlite3/backup.go b/vendor/github.com/ncruces/go-sqlite3/backup.go
deleted file mode 100644
index 58b6229a7..000000000
--- a/vendor/github.com/ncruces/go-sqlite3/backup.go
+++ /dev/null
@@ -1,134 +0,0 @@
-package sqlite3
-
-// Backup is an handle to an ongoing online backup operation.
-//
-// https://sqlite.org/c3ref/backup.html
-type Backup struct {
- c *Conn
- handle ptr_t
- otherc ptr_t
-}
-
-// Backup backs up srcDB on the src connection to the "main" database in dstURI.
-//
-// Backup opens the SQLite database file dstURI,
-// and blocks until the entire backup is complete.
-// Use [Conn.BackupInit] for incremental backup.
-//
-// https://sqlite.org/backup.html
-func (src *Conn) Backup(srcDB, dstURI string) error {
- b, err := src.BackupInit(srcDB, dstURI)
- if err != nil {
- return err
- }
- defer b.Close()
- _, err = b.Step(-1)
- return err
-}
-
-// Restore restores dstDB on the dst connection from the "main" database in srcURI.
-//
-// Restore opens the SQLite database file srcURI,
-// and blocks until the entire restore is complete.
-//
-// https://sqlite.org/backup.html
-func (dst *Conn) Restore(dstDB, srcURI string) error {
- src, err := dst.openDB(srcURI, OPEN_READONLY|OPEN_URI)
- if err != nil {
- return err
- }
- b, err := dst.backupInit(dst.handle, dstDB, src, "main")
- if err != nil {
- return err
- }
- defer b.Close()
- _, err = b.Step(-1)
- return err
-}
-
-// BackupInit initializes a backup operation to copy the content of one database into another.
-//
-// BackupInit opens the SQLite database file dstURI,
-// then initializes a backup that copies the contents of srcDB on the src connection
-// to the "main" database in dstURI.
-//
-// https://sqlite.org/c3ref/backup_finish.html#sqlite3backupinit
-func (src *Conn) BackupInit(srcDB, dstURI string) (*Backup, error) {
- dst, err := src.openDB(dstURI, OPEN_READWRITE|OPEN_CREATE|OPEN_URI)
- if err != nil {
- return nil, err
- }
- return src.backupInit(dst, "main", src.handle, srcDB)
-}
-
-func (c *Conn) backupInit(dst ptr_t, dstName string, src ptr_t, srcName string) (*Backup, error) {
- defer c.arena.mark()()
- dstPtr := c.arena.string(dstName)
- srcPtr := c.arena.string(srcName)
-
- other := dst
- if c.handle == dst {
- other = src
- }
-
- ptr := ptr_t(c.call("sqlite3_backup_init",
- stk_t(dst), stk_t(dstPtr),
- stk_t(src), stk_t(srcPtr)))
- if ptr == 0 {
- defer c.closeDB(other)
- rc := res_t(c.call("sqlite3_errcode", stk_t(dst)))
- return nil, c.sqlite.error(rc, dst)
- }
-
- return &Backup{
- c: c,
- otherc: other,
- handle: ptr,
- }, nil
-}
-
-// Close finishes a backup operation.
-//
-// It is safe to close a nil, zero or closed Backup.
-//
-// https://sqlite.org/c3ref/backup_finish.html#sqlite3backupfinish
-func (b *Backup) Close() error {
- if b == nil || b.handle == 0 {
- return nil
- }
-
- rc := res_t(b.c.call("sqlite3_backup_finish", stk_t(b.handle)))
- b.c.closeDB(b.otherc)
- b.handle = 0
- return b.c.error(rc)
-}
-
-// Step copies up to nPage pages between the source and destination databases.
-// If nPage is negative, all remaining source pages are copied.
-//
-// https://sqlite.org/c3ref/backup_finish.html#sqlite3backupstep
-func (b *Backup) Step(nPage int) (done bool, err error) {
- rc := res_t(b.c.call("sqlite3_backup_step", stk_t(b.handle), stk_t(nPage)))
- if rc == _DONE {
- return true, nil
- }
- return false, b.c.error(rc)
-}
-
-// Remaining returns the number of pages still to be backed up
-// at the conclusion of the most recent [Backup.Step].
-//
-// https://sqlite.org/c3ref/backup_finish.html#sqlite3backupremaining
-func (b *Backup) Remaining() int {
- n := int32(b.c.call("sqlite3_backup_remaining", stk_t(b.handle)))
- return int(n)
-}
-
-// PageCount returns the total number of pages in the source database
-// at the conclusion of the most recent [Backup.Step].
-//
-// https://sqlite.org/c3ref/backup_finish.html#sqlite3backuppagecount
-func (b *Backup) PageCount() int {
- n := int32(b.c.call("sqlite3_backup_pagecount", stk_t(b.handle)))
- return int(n)
-}