summaryrefslogtreecommitdiff
path: root/pkg/database/locks.go
diff options
context:
space:
mode:
authorJulien Dessaux2024-11-13 21:08:48 +0100
committerJulien Dessaux2024-11-13 21:08:48 +0100
commit4020344eda4d2a988f11dc60ac7c55a97aa39774 (patch)
treec5a6da4f1ddfea23642e0598f9623e18ac4f1659 /pkg/database/locks.go
parentchore(deps): update dependencies (diff)
downloadtfstated-4020344eda4d2a988f11dc60ac7c55a97aa39774.tar.gz
tfstated-4020344eda4d2a988f11dc60ac7c55a97aa39774.tar.bz2
tfstated-4020344eda4d2a988f11dc60ac7c55a97aa39774.zip
chore(tfstated): rename state "name" to "path" for consistency
Diffstat (limited to 'pkg/database/locks.go')
-rw-r--r--pkg/database/locks.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/pkg/database/locks.go b/pkg/database/locks.go
index 82b66cd..6951337 100644
--- a/pkg/database/locks.go
+++ b/pkg/database/locks.go
@@ -9,7 +9,7 @@ import (
// Atomically check the lock status of a state and lock it if unlocked. Returns
// true if the function locked the state, otherwise returns false and the lock
// parameter is updated to the value of the existing lock
-func (db *DB) SetLockOrGetExistingLock(name string, lock any) (bool, error) {
+func (db *DB) SetLockOrGetExistingLock(path string, lock any) (bool, error) {
tx, err := db.Begin()
if err != nil {
return false, err
@@ -20,12 +20,12 @@ func (db *DB) SetLockOrGetExistingLock(name string, lock any) (bool, error) {
}
}()
var lockData []byte
- if err = tx.QueryRowContext(db.ctx, `SELECT lock FROM states WHERE name = ?;`, name).Scan(&lockData); err != nil {
+ if err = tx.QueryRowContext(db.ctx, `SELECT lock FROM states WHERE path = ?;`, path).Scan(&lockData); err != nil {
if errors.Is(err, sql.ErrNoRows) {
if lockData, err = json.Marshal(lock); err != nil {
return false, err
}
- _, err = tx.ExecContext(db.ctx, `INSERT INTO states(name, lock) VALUES (?, json(?))`, name, lockData)
+ _, err = tx.ExecContext(db.ctx, `INSERT INTO states(path, lock) VALUES (?, json(?))`, path, lockData)
if err != nil {
return false, err
}
@@ -43,7 +43,7 @@ func (db *DB) SetLockOrGetExistingLock(name string, lock any) (bool, error) {
if lockData, err = json.Marshal(lock); err != nil {
return false, err
}
- _, err = tx.ExecContext(db.ctx, `UPDATE states SET lock = json(?) WHERE name = ?;`, lockData, name)
+ _, err = tx.ExecContext(db.ctx, `UPDATE states SET lock = json(?) WHERE path = ?;`, lockData, path)
if err != nil {
return false, err
}
@@ -51,12 +51,12 @@ func (db *DB) SetLockOrGetExistingLock(name string, lock any) (bool, error) {
return true, err
}
-func (db *DB) Unlock(name, lock any) (bool, error) {
+func (db *DB) Unlock(path, lock any) (bool, error) {
data, err := json.Marshal(lock)
if err != nil {
return false, err
}
- result, err := db.Exec(`UPDATE states SET lock = NULL WHERE name = ? and lock = json(?);`, name, data)
+ result, err := db.Exec(`UPDATE states SET lock = NULL WHERE path = ? and lock = json(?);`, path, data)
if err != nil {
return false, err
}