diff options
author | Daniel J Walsh <dwalsh@redhat.com> | 2017-11-20 14:45:01 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-20 14:45:01 -0500 |
commit | 6e0944f2f128534caaf884251d1e42fa4f1ba235 (patch) | |
tree | 4ecca5c1388b93de16b1dd91244ffb3488b0ddd1 /vendor/github.com/mattn/go-sqlite3/backup.go | |
parent | 3e04604dc2619b1502b609083c3b6ecb0949f1d5 (diff) | |
parent | f2894eda689a24c069b55b1e2ad3e6136836b326 (diff) | |
download | podman-6e0944f2f128534caaf884251d1e42fa4f1ba235.tar.gz podman-6e0944f2f128534caaf884251d1e42fa4f1ba235.tar.bz2 podman-6e0944f2f128534caaf884251d1e42fa4f1ba235.zip |
Merge pull request #26 from mheon/sql_state
Implementation of SQL-backed state
Diffstat (limited to 'vendor/github.com/mattn/go-sqlite3/backup.go')
-rw-r--r-- | vendor/github.com/mattn/go-sqlite3/backup.go | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/vendor/github.com/mattn/go-sqlite3/backup.go b/vendor/github.com/mattn/go-sqlite3/backup.go new file mode 100644 index 000000000..5ab3a54de --- /dev/null +++ b/vendor/github.com/mattn/go-sqlite3/backup.go @@ -0,0 +1,85 @@ +// Copyright (C) 2014 Yasuhiro Matsumoto <mattn.jp@gmail.com>. +// +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file. + +package sqlite3 + +/* +#ifndef USE_LIBSQLITE3 +#include <sqlite3-binding.h> +#else +#include <sqlite3.h> +#endif +#include <stdlib.h> +*/ +import "C" +import ( + "runtime" + "unsafe" +) + +// SQLiteBackup implement interface of Backup. +type SQLiteBackup struct { + b *C.sqlite3_backup +} + +// Backup make backup from src to dest. +func (c *SQLiteConn) Backup(dest string, conn *SQLiteConn, src string) (*SQLiteBackup, error) { + destptr := C.CString(dest) + defer C.free(unsafe.Pointer(destptr)) + srcptr := C.CString(src) + defer C.free(unsafe.Pointer(srcptr)) + + if b := C.sqlite3_backup_init(c.db, destptr, conn.db, srcptr); b != nil { + bb := &SQLiteBackup{b: b} + runtime.SetFinalizer(bb, (*SQLiteBackup).Finish) + return bb, nil + } + return nil, c.lastError() +} + +// Step to backs up for one step. Calls the underlying `sqlite3_backup_step` +// function. This function returns a boolean indicating if the backup is done +// and an error signalling any other error. Done is returned if the underlying +// C function returns SQLITE_DONE (Code 101) +func (b *SQLiteBackup) Step(p int) (bool, error) { + ret := C.sqlite3_backup_step(b.b, C.int(p)) + if ret == C.SQLITE_DONE { + return true, nil + } else if ret != 0 && ret != C.SQLITE_LOCKED && ret != C.SQLITE_BUSY { + return false, Error{Code: ErrNo(ret)} + } + return false, nil +} + +// Remaining return whether have the rest for backup. +func (b *SQLiteBackup) Remaining() int { + return int(C.sqlite3_backup_remaining(b.b)) +} + +// PageCount return count of pages. +func (b *SQLiteBackup) PageCount() int { + return int(C.sqlite3_backup_pagecount(b.b)) +} + +// Finish close backup. +func (b *SQLiteBackup) Finish() error { + return b.Close() +} + +// Close close backup. +func (b *SQLiteBackup) Close() error { + ret := C.sqlite3_backup_finish(b.b) + + // sqlite3_backup_finish() never fails, it just returns the + // error code from previous operations, so clean up before + // checking and returning an error + b.b = nil + runtime.SetFinalizer(b, nil) + + if ret != 0 { + return Error{Code: ErrNo(ret)} + } + return nil +} |