Skip to content

Commit 8887036

Browse files
committed
SQLITE_FCNTL_SYNC.
1 parent ccb3dcd commit 8887036

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

vfs/api.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ type FileOverwrite interface {
121121
Overwrite() error
122122
}
123123

124+
// FileSync extends File to implement the
125+
// SQLITE_FCNTL_SYNC file control opcode.
126+
//
127+
// https://sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntlsync
128+
type FileSync interface {
129+
File
130+
SyncSuper(super string) error
131+
}
132+
124133
// FileCommitPhaseTwo extends File to implement the
125134
// SQLITE_FCNTL_COMMIT_PHASETWO file control opcode.
126135
//

vfs/vfs.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,16 @@ func vfsFileControlImpl(ctx context.Context, mod api.Module, file File, op _Fcnt
309309
return vfsErrorCode(err, _IOERR)
310310
}
311311

312+
case _FCNTL_SYNC:
313+
if file, ok := file.(FileSync); ok {
314+
var name string
315+
if pArg != 0 {
316+
name = util.ReadString(mod, pArg, _MAX_PATHNAME)
317+
}
318+
err := file.SyncSuper(name)
319+
return vfsErrorCode(err, _IOERR)
320+
}
321+
312322
case _FCNTL_COMMIT_PHASETWO:
313323
if file, ok := file.(FileCommitPhaseTwo); ok {
314324
err := file.CommitPhaseTwo()
@@ -384,10 +394,6 @@ func vfsFileControlImpl(ctx context.Context, mod api.Module, file File, op _Fcnt
384394
}
385395
}
386396

387-
// Consider also implementing these opcodes (in use by SQLite):
388-
// _FCNTL_BUSYHANDLER
389-
// _FCNTL_LAST_ERRNO
390-
// _FCNTL_SYNC
391397
return _NOTFOUND
392398
}
393399

0 commit comments

Comments
 (0)