Skip to content

Commit

Permalink
SQLITE_FCNTL_SYNC.
Browse files Browse the repository at this point in the history
  • Loading branch information
ncruces committed Jan 14, 2025
1 parent ccb3dcd commit 8887036
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
9 changes: 9 additions & 0 deletions vfs/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ type FileOverwrite interface {
Overwrite() error
}

// FileSync extends File to implement the
// SQLITE_FCNTL_SYNC file control opcode.
//
// https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntlsync
type FileSync interface {
File
SyncSuper(super string) error
}

// FileCommitPhaseTwo extends File to implement the
// SQLITE_FCNTL_COMMIT_PHASETWO file control opcode.
//
Expand Down
14 changes: 10 additions & 4 deletions vfs/vfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,16 @@ func vfsFileControlImpl(ctx context.Context, mod api.Module, file File, op _Fcnt
return vfsErrorCode(err, _IOERR)
}

case _FCNTL_SYNC:
if file, ok := file.(FileSync); ok {
var name string
if pArg != 0 {
name = util.ReadString(mod, pArg, _MAX_PATHNAME)
}
err := file.SyncSuper(name)
return vfsErrorCode(err, _IOERR)
}

case _FCNTL_COMMIT_PHASETWO:
if file, ok := file.(FileCommitPhaseTwo); ok {
err := file.CommitPhaseTwo()
Expand Down Expand Up @@ -384,10 +394,6 @@ func vfsFileControlImpl(ctx context.Context, mod api.Module, file File, op _Fcnt
}
}

// Consider also implementing these opcodes (in use by SQLite):
// _FCNTL_BUSYHANDLER
// _FCNTL_LAST_ERRNO
// _FCNTL_SYNC
return _NOTFOUND
}

Expand Down

0 comments on commit 8887036

Please sign in to comment.