mirror of
https://github.com/Luzifer/cloudbox.git
synced 2024-12-22 18:51:21 +00:00
Fix linter advices
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
f4227214de
commit
c658048ad1
5 changed files with 13 additions and 30 deletions
|
@ -17,9 +17,9 @@ type shareConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type syncConfig struct {
|
type syncConfig struct {
|
||||||
LocalDir string `yaml:"local_dir"`
|
LocalDir string `yaml:"local_dir"`
|
||||||
RemoteURI string `yaml:"remote_uri"`
|
RemoteURI string `yaml:"remote_uri"`
|
||||||
Settings sync.SyncConfig `yaml:"settings"`
|
Settings sync.Config `yaml:"settings"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type configFile struct {
|
type configFile struct {
|
||||||
|
@ -48,7 +48,7 @@ func defaultConfig() *configFile {
|
||||||
return &configFile{
|
return &configFile{
|
||||||
ControlDir: "~/.cache/cloudbox",
|
ControlDir: "~/.cache/cloudbox",
|
||||||
Sync: syncConfig{
|
Sync: syncConfig{
|
||||||
Settings: sync.SyncConfig{
|
Settings: sync.Config{
|
||||||
ScanInterval: time.Minute,
|
ScanInterval: time.Minute,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -27,7 +27,7 @@ func (c Change) Changed() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Change) Register(add Change) {
|
func (c *Change) Register(add Change) {
|
||||||
*c = *c | add
|
*c |= add
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Change) HasAll(test ...Change) bool {
|
func (c Change) HasAll(test ...Change) bool {
|
||||||
|
|
23
sync/db.go
23
sync/db.go
|
@ -1,7 +1,6 @@
|
||||||
package sync
|
package sync
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -30,6 +29,7 @@ func (s *Sync) initSchema() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sync) deleteDBFileInfo(side, relativeName string) error {
|
func (s *Sync) deleteDBFileInfo(side, relativeName string) error {
|
||||||
|
// #nosec G201 - fmt is only used to prefix a table with a constant, no user input
|
||||||
stmt, err := s.db.Prepare(fmt.Sprintf(`DELETE FROM %s_state WHERE relative_name = ?`, side))
|
stmt, err := s.db.Prepare(fmt.Sprintf(`DELETE FROM %s_state WHERE relative_name = ?`, side))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Unable to prepare query")
|
return errors.Wrap(err, "Unable to prepare query")
|
||||||
|
@ -39,26 +39,8 @@ func (s *Sync) deleteDBFileInfo(side, relativeName string) error {
|
||||||
return errors.Wrap(err, "Unable to delete file info")
|
return errors.Wrap(err, "Unable to delete file info")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sync) getDBFileInfo(side, relativeName string) (providers.FileInfo, error) {
|
|
||||||
info := providers.FileInfo{}
|
|
||||||
|
|
||||||
stmt, err := s.db.Prepare(fmt.Sprintf("SELECT * from %s_state WHERE relative_name = ?", side))
|
|
||||||
if err != nil {
|
|
||||||
return info, errors.Wrap(err, "Unable to prepare query")
|
|
||||||
}
|
|
||||||
|
|
||||||
row := stmt.QueryRow(relativeName)
|
|
||||||
if err = row.Scan(&info.RelativeName, &info.LastModified, &info.Checksum, &info.Size); err != nil {
|
|
||||||
if err == sql.ErrNoRows {
|
|
||||||
return info, providers.ErrFileNotFound
|
|
||||||
}
|
|
||||||
return info, errors.Wrap(err, "Unable to read response")
|
|
||||||
}
|
|
||||||
|
|
||||||
return info, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Sync) setDBFileInfo(side string, info providers.FileInfo) error {
|
func (s *Sync) setDBFileInfo(side string, info providers.FileInfo) error {
|
||||||
|
// #nosec G201 - fmt is only used to prefix a table with a constant, no user input
|
||||||
stmt, err := s.db.Prepare(fmt.Sprintf(
|
stmt, err := s.db.Prepare(fmt.Sprintf(
|
||||||
`INSERT INTO %s_state VALUES(?, ?, ?, ?)
|
`INSERT INTO %s_state VALUES(?, ?, ?, ?)
|
||||||
ON CONFLICT(relative_name) DO UPDATE SET
|
ON CONFLICT(relative_name) DO UPDATE SET
|
||||||
|
@ -75,6 +57,7 @@ func (s *Sync) setDBFileInfo(side string, info providers.FileInfo) error {
|
||||||
|
|
||||||
func (s *Sync) updateStateFromDatabase(st *state) error {
|
func (s *Sync) updateStateFromDatabase(st *state) error {
|
||||||
for _, table := range []string{sideLocal, sideRemote} {
|
for _, table := range []string{sideLocal, sideRemote} {
|
||||||
|
// #nosec G201 - fmt is only used to prefix a table with a constant, no user input
|
||||||
rows, err := s.db.Query(fmt.Sprintf("SELECT * FROM %s_state", table))
|
rows, err := s.db.Query(fmt.Sprintf("SELECT * FROM %s_state", table))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Unable to query table %s", table)
|
return errors.Wrapf(err, "Unable to query table %s", table)
|
||||||
|
|
|
@ -49,7 +49,7 @@ func (s *state) GetChangeFor(relativeName string) (result Change) {
|
||||||
result.Register(ChangeLocalAdd)
|
result.Register(ChangeLocalAdd)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for local changes
|
// Check for local changes
|
||||||
|
@ -76,7 +76,7 @@ func (s *state) GetChangeFor(relativeName string) (result Change) {
|
||||||
result.Register(ChangeRemoteUpdate)
|
result.Register(ChangeRemoteUpdate)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state) GetRelativeNames() []string {
|
func (s *state) GetRelativeNames() []string {
|
||||||
|
|
|
@ -11,14 +11,14 @@ import (
|
||||||
"github.com/Luzifer/cloudbox/providers"
|
"github.com/Luzifer/cloudbox/providers"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SyncConfig struct {
|
type Config struct {
|
||||||
ForceUseChecksum bool `yaml:"force_use_checksum"`
|
ForceUseChecksum bool `yaml:"force_use_checksum"`
|
||||||
ScanInterval time.Duration `yaml:"scan_interval"`
|
ScanInterval time.Duration `yaml:"scan_interval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Sync struct {
|
type Sync struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
conf SyncConfig
|
conf Config
|
||||||
local, remote providers.CloudProvider
|
local, remote providers.CloudProvider
|
||||||
|
|
||||||
log *log.Entry
|
log *log.Entry
|
||||||
|
@ -26,7 +26,7 @@ type Sync struct {
|
||||||
stop chan struct{}
|
stop chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(local, remote providers.CloudProvider, db *sql.DB, conf SyncConfig, logger *log.Entry) *Sync {
|
func New(local, remote providers.CloudProvider, db *sql.DB, conf Config, logger *log.Entry) *Sync {
|
||||||
return &Sync{
|
return &Sync{
|
||||||
db: db,
|
db: db,
|
||||||
conf: conf,
|
conf: conf,
|
||||||
|
|
Loading…
Reference in a new issue