mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2025-09-06 10:30:39 +00:00
chore: move lockfile code to internal module
In a future commit, I'll need the lockfile code to access the config file. This solves an import cycle.
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
"github.com/cupcakearmy/autorestic/internal/colors"
|
||||
"github.com/cupcakearmy/autorestic/internal/flags"
|
||||
"github.com/cupcakearmy/autorestic/internal/lock"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/mitchellh/go-homedir"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -40,7 +39,7 @@ func exitConfig(err error, msg string) {
|
||||
if msg != "" {
|
||||
colors.Error.Println(msg)
|
||||
}
|
||||
lock.Unlock()
|
||||
Unlock()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
@@ -11,7 +11,6 @@ import (
|
||||
|
||||
"github.com/cupcakearmy/autorestic/internal/colors"
|
||||
"github.com/cupcakearmy/autorestic/internal/flags"
|
||||
"github.com/cupcakearmy/autorestic/internal/lock"
|
||||
"github.com/cupcakearmy/autorestic/internal/metadata"
|
||||
"github.com/robfig/cron"
|
||||
)
|
||||
@@ -442,11 +441,11 @@ func (l Location) RunCron() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
last := time.Unix(lock.GetCron(l.name), 0)
|
||||
last := time.Unix(GetCron(l.name), 0)
|
||||
next := schedule.Next(last)
|
||||
now := time.Now()
|
||||
if now.After(next) {
|
||||
lock.SetCron(l.name, now.Unix())
|
||||
SetCron(l.name, now.Unix())
|
||||
errs := l.Backup(true, "")
|
||||
if len(errs) > 0 {
|
||||
return fmt.Errorf("Failed to backup location \"%s\":\n%w", l.name, errors.Join(errs...))
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package lock
|
||||
package internal
|
||||
|
||||
import (
|
||||
"os"
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
var lock *viper.Viper
|
||||
var file string
|
||||
var once sync.Once
|
||||
var lockOnce sync.Once
|
||||
|
||||
const (
|
||||
RUNNING = "running"
|
||||
@@ -36,7 +36,7 @@ func getLockfilePath() string {
|
||||
|
||||
func getLock() *viper.Viper {
|
||||
if lock == nil {
|
||||
once.Do(func() {
|
||||
lockOnce.Do(func() {
|
||||
lock = viper.New()
|
||||
lock.SetDefault("running", false)
|
||||
file = getLockfilePath()
|
@@ -1,4 +1,4 @@
|
||||
package lock
|
||||
package internal
|
||||
|
||||
import (
|
||||
"log"
|
Reference in New Issue
Block a user