summaryrefslogtreecommitdiff
path: root/internal/namespace/pinning.go
diff options
context:
space:
mode:
authorJames O'Doherty <james@theodohertyfamily.com>2026-05-22 16:17:55 -0400
committerJames O'Doherty <james@theodohertyfamily.com>2026-05-22 16:17:55 -0400
commit135f6edbd9389bc4783f13c26aed0a74d3c8aca0 (patch)
tree41a8e80b0dcf2c42b045bc91d9101deceb049f47 /internal/namespace/pinning.go
parent2e3a1d07b43e6e942e51ba263c6fcdc2351afc0d (diff)
refactor: unify path management and complete profile management system
- Create internal/paths package for unified config and runtime directory resolution - Implement robust WireGuard config parsing in pkg/wgconf - Implement profile management subcommands: list, import, configure, delete, stop - Fix namespace pinning path collisions (separating .ns files from pids directories) - Implement and verify namespace unpinning logic - Fix linting errors and improve error handling across the project
Diffstat (limited to 'internal/namespace/pinning.go')
-rw-r--r--internal/namespace/pinning.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/internal/namespace/pinning.go b/internal/namespace/pinning.go
new file mode 100644
index 0000000..cd81a38
--- /dev/null
+++ b/internal/namespace/pinning.go
@@ -0,0 +1,35 @@
+package namespace
+
+import (
+ "fmt"
+ "os"
+
+ "git.theodohertyfamily.com/tools/wg-wrap/internal/paths"
+)
+
+// UnpinNamespace removes the pinned namespace file from the filesystem.
+// This allows the namespace to be destroyed once the last process exits.
+func UnpinNamespace(pm *paths.PathManager, profile string) error {
+ nsPath := GetProfileNamespacePath(pm, profile)
+
+ // We only want to unpin if there are no more active processes.
+ // The caller (cli.ExecuteCommand) is responsible for calling this
+ // when IsLastProcess returns true.
+
+ if _, err := os.Stat(nsPath); os.IsNotExist(err) {
+ return nil
+ }
+
+ // We also want to remove the pids directory if it's empty.
+ pidsDir := GetPidsDirPath(pm, profile)
+
+ // Unlink the namespace file
+ if err := os.Remove(nsPath); err != nil {
+ return fmt.Errorf("failed to unpin namespace %s: %w", nsPath, err)
+ }
+
+ // Try to remove pids directory
+ _ = os.Remove(pidsDir)
+
+ return nil
+}