1
0
mirror of https://github.com/Luzifer/cloudbox.git synced 2024-09-19 15:12:55 +00:00

Fix linter advices

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-06-16 23:10:54 +02:00
parent f4227214de
commit c658048ad1
Signed by: luzifer
GPG Key ID: DC2729FDD34BE99E
5 changed files with 13 additions and 30 deletions

View File

@ -19,7 +19,7 @@ type shareConfig struct {
type syncConfig struct {
LocalDir string `yaml:"local_dir"`
RemoteURI string `yaml:"remote_uri"`
Settings sync.SyncConfig `yaml:"settings"`
Settings sync.Config `yaml:"settings"`
}
type configFile struct {
@ -48,7 +48,7 @@ func defaultConfig() *configFile {
return &configFile{
ControlDir: "~/.cache/cloudbox",
Sync: syncConfig{
Settings: sync.SyncConfig{
Settings: sync.Config{
ScanInterval: time.Minute,
},
},

View File

@ -27,7 +27,7 @@ func (c Change) Changed() bool {
}
func (c *Change) Register(add Change) {
*c = *c | add
*c |= add
}
func (c Change) HasAll(test ...Change) bool {

View File

@ -1,7 +1,6 @@
package sync
import (
"database/sql"
"fmt"
"github.com/pkg/errors"
@ -30,6 +29,7 @@ func (s *Sync) initSchema() 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))
if err != nil {
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")
}
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 {
// #nosec G201 - fmt is only used to prefix a table with a constant, no user input
stmt, err := s.db.Prepare(fmt.Sprintf(
`INSERT INTO %s_state VALUES(?, ?, ?, ?)
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 {
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))
if err != nil {
return errors.Wrapf(err, "Unable to query table %s", table)

View File

@ -49,7 +49,7 @@ func (s *state) GetChangeFor(relativeName string) (result Change) {
result.Register(ChangeLocalAdd)
}
return
return result
}
// Check for local changes
@ -76,7 +76,7 @@ func (s *state) GetChangeFor(relativeName string) (result Change) {
result.Register(ChangeRemoteUpdate)
}
return
return result
}
func (s *state) GetRelativeNames() []string {

View File

@ -11,14 +11,14 @@ import (
"github.com/Luzifer/cloudbox/providers"
)
type SyncConfig struct {
type Config struct {
ForceUseChecksum bool `yaml:"force_use_checksum"`
ScanInterval time.Duration `yaml:"scan_interval"`
}
type Sync struct {
db *sql.DB
conf SyncConfig
conf Config
local, remote providers.CloudProvider
log *log.Entry
@ -26,7 +26,7 @@ type Sync 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{
db: db,
conf: conf,