2014-12-07 13:21:12 -07:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
|
|
|
//
|
2015-03-07 13:36:35 -07:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
2017-02-08 23:52:18 -07:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2014-12-07 13:21:12 -07:00
|
|
|
|
|
|
|
package stats
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2015-08-06 02:29:25 -07:00
|
|
|
"github.com/syncthing/syncthing/lib/db"
|
2014-12-07 13:21:12 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
type FolderStatistics struct {
|
2016-06-02 12:26:52 -07:00
|
|
|
LastFile LastFile `json:"lastFile"`
|
|
|
|
LastScan time.Time `json:"lastScan"`
|
2014-12-07 13:21:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type FolderStatisticsReference struct {
|
2015-01-17 12:53:33 -07:00
|
|
|
ns *db.NamespacedKV
|
2014-12-07 13:21:12 -07:00
|
|
|
folder string
|
|
|
|
}
|
|
|
|
|
2015-01-17 12:53:33 -07:00
|
|
|
type LastFile struct {
|
2015-03-10 15:45:43 -07:00
|
|
|
At time.Time `json:"at"`
|
|
|
|
Filename string `json:"filename"`
|
2015-06-16 04:12:34 -07:00
|
|
|
Deleted bool `json:"deleted"`
|
2015-01-17 12:53:33 -07:00
|
|
|
}
|
|
|
|
|
2018-10-10 02:34:24 -07:00
|
|
|
func NewFolderStatisticsReference(ldb *db.Lowlevel, folder string) *FolderStatisticsReference {
|
2014-12-07 13:21:12 -07:00
|
|
|
return &FolderStatisticsReference{
|
2018-10-10 02:34:24 -07:00
|
|
|
ns: db.NewFolderStatisticsNamespace(ldb, folder),
|
2014-12-07 13:21:12 -07:00
|
|
|
folder: folder,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-17 12:53:33 -07:00
|
|
|
func (s *FolderStatisticsReference) GetLastFile() LastFile {
|
|
|
|
at, ok := s.ns.Time("lastFileAt")
|
|
|
|
if !ok {
|
|
|
|
return LastFile{}
|
2014-12-07 13:21:12 -07:00
|
|
|
}
|
2015-01-17 12:53:33 -07:00
|
|
|
file, ok := s.ns.String("lastFileName")
|
|
|
|
if !ok {
|
|
|
|
return LastFile{}
|
|
|
|
}
|
2016-07-15 07:23:20 -07:00
|
|
|
deleted, _ := s.ns.Bool("lastFileDeleted")
|
2015-01-17 12:53:33 -07:00
|
|
|
return LastFile{
|
|
|
|
At: at,
|
|
|
|
Filename: file,
|
2015-06-16 04:12:34 -07:00
|
|
|
Deleted: deleted,
|
2014-12-07 13:21:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-04 04:22:59 -07:00
|
|
|
func (s *FolderStatisticsReference) ReceivedFile(file string, deleted bool) {
|
2015-10-03 08:25:21 -07:00
|
|
|
l.Debugln("stats.FolderStatisticsReference.ReceivedFile:", s.folder, file)
|
2015-01-17 12:53:33 -07:00
|
|
|
s.ns.PutTime("lastFileAt", time.Now())
|
2015-09-04 04:22:59 -07:00
|
|
|
s.ns.PutString("lastFileName", file)
|
|
|
|
s.ns.PutBool("lastFileDeleted", deleted)
|
2014-12-07 13:21:12 -07:00
|
|
|
}
|
|
|
|
|
2016-06-02 12:26:52 -07:00
|
|
|
func (s *FolderStatisticsReference) ScanCompleted() {
|
|
|
|
s.ns.PutTime("lastScan", time.Now())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *FolderStatisticsReference) GetLastScanTime() time.Time {
|
|
|
|
lastScan, ok := s.ns.Time("lastScan")
|
|
|
|
if !ok {
|
|
|
|
return time.Time{}
|
|
|
|
}
|
|
|
|
return lastScan
|
|
|
|
}
|
|
|
|
|
2014-12-07 13:21:12 -07:00
|
|
|
func (s *FolderStatisticsReference) GetStatistics() FolderStatistics {
|
|
|
|
return FolderStatistics{
|
|
|
|
LastFile: s.GetLastFile(),
|
2016-06-02 12:26:52 -07:00
|
|
|
LastScan: s.GetLastScanTime(),
|
2014-12-07 13:21:12 -07:00
|
|
|
}
|
|
|
|
}
|