| 1669 | } |
| 1670 | |
| 1671 | func (f *VFSFile) Sync(flag sqlite3vfs.SyncType) error { |
| 1672 | f.logger.Debug("syncing file", "flag", flag) |
| 1673 | |
| 1674 | f.mu.Lock() |
| 1675 | defer f.mu.Unlock() |
| 1676 | |
| 1677 | // If write support is not enabled, no-op |
| 1678 | if !f.writeEnabled { |
| 1679 | return nil |
| 1680 | } |
| 1681 | |
| 1682 | // Skip sync if no dirty pages |
| 1683 | if len(f.dirty) == 0 { |
| 1684 | return nil |
| 1685 | } |
| 1686 | // Skip sync during active transaction |
| 1687 | if f.inTransaction { |
| 1688 | f.logger.Debug("skipping sync during transaction") |
| 1689 | return nil |
| 1690 | } |
| 1691 | |
| 1692 | return f.syncToRemoteWithLock() |
| 1693 | } |
| 1694 | |
| 1695 | // SetWriteEnabled enables or disables write support at runtime. |
| 1696 | // This is equivalent to SetWriteEnabledWithTimeout(enabled, 0) which waits indefinitely. |