1
0
Fork 0
mirror of https://github.com/imjasonh/cnotes synced 2026-07-09 09:29:24 +00:00

Prevent cnotes installation from temporary directories

- Add check for os.TempDir() and /tmp/ prefix
- Resolve symlinks to handle macOS temp directory structure
- Guide users to use 'go install' for proper installation
This commit is contained in:
Jason Hall 2025-07-21 14:57:34 -04:00
parent 3cfe51703e
commit 47abf1a0ce
Failed to extract signature
2 changed files with 395 additions and 1 deletions

View file

@ -5,6 +5,7 @@ import (
"log/slog"
"os"
"path/filepath"
"strings"
"github.com/imjasonh/cnotes/internal/config"
"github.com/spf13/cobra"
@ -66,6 +67,21 @@ func runInstall(cmd *cobra.Command, args []string) error {
scope = "project"
}
// Prevent installation from temporary directories (unless uninstalling)
if !uninstall {
tempDir := os.TempDir()
// Resolve any symlinks in the executable path for comparison
realExecutable, err := filepath.EvalSymlinks(executable)
if err != nil {
realExecutable = executable // Fall back to original if can't resolve
}
// Check if executable is in temp directory
if strings.HasPrefix(realExecutable, tempDir) || strings.HasPrefix(executable, "/tmp/") {
return fmt.Errorf("cannot install from temporary directory: %s\nPlease build and install cnotes properly:\n go install && cnotes install", executable)
}
}
if uninstall {
slog.Info("uninstalling hooks", "binary", executable, "scope", scope)
if err := config.UninstallHooksFromPath(executable, settingsPath); err != nil {