Add native session initialization and remote lock commands

This commit is contained in:
2026-11-20 05:29:27 +00:00
parent e44247b5b1
commit 6b7a0847d4
8 changed files with 606 additions and 130 deletions

View File

@@ -2,7 +2,6 @@ package app
import (
"context"
"errors"
"flag"
"fmt"
"io"
@@ -69,25 +68,10 @@ func locksAddWithDependencies(ctx context.Context, args []string, out io.Writer,
return fmt.Errorf("locks add: %w", err)
}
defer cleanup()
lock, err := artifacts.NewRemoteLock(source, strings.TrimSpace(reason), nowUTC())
_, err = applyRemoteLockMutation(ctx, store, sessionPrefix, "add", source, reason, force)
if err != nil {
return fmt.Errorf("locks add: %w", err)
}
if !force {
current, err := artifacts.LookupRemoteLock(ctx, store, sessionPrefix, source)
if err != nil {
return fmt.Errorf("locks add: %w", err)
}
if current.Present {
return fmt.Errorf("locks add: remote lock for %q already exists; pass --force to update", source)
}
}
if err := artifacts.AddRemoteLock(ctx, store, sessionPrefix, lock, force); err != nil {
if errors.Is(err, storage.ErrConditionNotMet) {
return fmt.Errorf("locks add: remote lock for %q changed concurrently; retry: %w", source, err)
}
return fmt.Errorf("locks add: %w", err)
}
_, err = fmt.Fprintf(out, "narratio session locks add: locked %s\n", source)
return err
}
@@ -114,14 +98,11 @@ func locksRemoveWithDependencies(ctx context.Context, args []string, out io.Writ
return fmt.Errorf("locks remove: %w", err)
}
defer cleanup()
current, err := artifacts.LookupRemoteLock(ctx, store, sessionPrefix, source)
result, err := applyRemoteLockMutation(ctx, store, sessionPrefix, "remove", source, "", false)
if err != nil {
return fmt.Errorf("locks remove: %w", err)
}
if err := artifacts.RemoveRemoteLock(ctx, store, sessionPrefix, source); err != nil {
return fmt.Errorf("locks remove: %w", err)
}
if !current.Present {
if result == "not_locked" {
_, err = fmt.Fprintf(out, "narratio session locks remove: %s was not locked\n", source)
return err
}