M1: make mount/unmount idempotent
mount now detects already-unlocked and already-mounted devices, returning the existing mount point instead of failing. unmount handles already-locked devices gracefully and skips unmount if not mounted before locking. Adds IsMounted helper to udisks client. Updates PLAN.md with refined v1.0.0 milestones. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,6 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.wntrmute.dev/kyle/arca/internal/config"
|
||||
"git.wntrmute.dev/kyle/arca/internal/cryptsetup"
|
||||
@@ -39,31 +38,27 @@ func runUnmount(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Check if already locked.
|
||||
cleartext, err := client.CleartextDevice(dev)
|
||||
if err != nil {
|
||||
return fmt.Errorf("finding cleartext device: %w", err)
|
||||
fmt.Fprintf(cmd.ErrOrStderr(), "%s is already locked\n", target)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Unmount: try udisks2 first, fall back to privileged umount.
|
||||
mp, _ := client.MountPoint(cleartext)
|
||||
if err := client.Unmount(cleartext); err != nil {
|
||||
if mp == "" {
|
||||
return fmt.Errorf("unmounting: %w", err)
|
||||
}
|
||||
if err := cryptsetup.Unmount(mp); err != nil {
|
||||
return fmt.Errorf("unmounting: %w", err)
|
||||
// Unmount if mounted.
|
||||
if mp, mounted := client.IsMounted(cleartext); mounted {
|
||||
if err := client.Unmount(cleartext); err != nil {
|
||||
// udisks2 unmount failed — try privileged umount.
|
||||
if err := cryptsetup.Unmount(mp); err != nil {
|
||||
return fmt.Errorf("unmounting: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Lock: try udisks2 first, fall back to cryptsetup close if it's
|
||||
// an arca-managed mapping.
|
||||
// Lock: try udisks2 first, fall back to cryptsetup close.
|
||||
if err := client.Lock(dev); err != nil {
|
||||
mapperName := cryptsetup.MapperName(dev.DevicePath)
|
||||
if strings.HasPrefix(mapperName, "arca-") {
|
||||
if err := cryptsetup.Close(mapperName); err != nil {
|
||||
return fmt.Errorf("locking: %w", err)
|
||||
}
|
||||
} else {
|
||||
if err := cryptsetup.Close(mapperName); err != nil {
|
||||
return fmt.Errorf("locking: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user