folderdb_mtimes.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (C) 2025 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package sqlite
  7. import (
  8. "time"
  9. )
  10. func (s *folderDB) GetMtime(name string) (ondisk, virtual time.Time) {
  11. var res struct {
  12. Ondisk int64
  13. Virtual int64
  14. }
  15. if err := s.stmt(`
  16. SELECT m.ondisk, m.virtual FROM mtimes m
  17. WHERE m.name = ?
  18. `).Get(&res, name); err != nil {
  19. return time.Time{}, time.Time{}
  20. }
  21. return time.Unix(0, res.Ondisk), time.Unix(0, res.Virtual)
  22. }
  23. func (s *folderDB) PutMtime(name string, ondisk, virtual time.Time) error {
  24. s.updateLock.Lock()
  25. defer s.updateLock.Unlock()
  26. _, err := s.stmt(`
  27. INSERT OR REPLACE INTO mtimes (name, ondisk, virtual)
  28. VALUES (?, ?, ?)
  29. `).Exec(name, ondisk.UnixNano(), virtual.UnixNano())
  30. return wrap(err)
  31. }
  32. func (s *folderDB) DeleteMtime(name string) error {
  33. s.updateLock.Lock()
  34. defer s.updateLock.Unlock()
  35. _, err := s.stmt(`
  36. DELETE FROM mtimes
  37. WHERE name = ?
  38. `).Exec(name)
  39. return wrap(err)
  40. }