mirror of
https://github.com/Mikescher/kpsync.git
synced 2025-10-25 22:25:09 +02:00
non-functional wip state
This commit is contained in:
47
app/utils.go
Normal file
47
app/utils.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/cryptext"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/exerr"
|
||||
)
|
||||
|
||||
func fileExists(p string) bool {
|
||||
_, err := os.Stat(p)
|
||||
if os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
type State struct {
|
||||
ETag string `json:"etag"`
|
||||
Size int64 `json:"size"`
|
||||
Checksum string `json:"checksum"`
|
||||
}
|
||||
|
||||
func (app *Application) readState() *State {
|
||||
bin, err := os.ReadFile(app.stateFile)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var state State
|
||||
err = json.Unmarshal(bin, &state)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &state
|
||||
}
|
||||
|
||||
func (app *Application) calcLocalChecksum() (string, error) {
|
||||
bin, err := os.ReadFile(app.dbFile)
|
||||
if err != nil {
|
||||
return "", exerr.Wrap(err, "").Build()
|
||||
}
|
||||
|
||||
return cryptext.BytesSha256(bin), nil
|
||||
}
|
||||
Reference in New Issue
Block a user