mirror of
https://github.com/safing/portmaster
synced 2025-09-01 18:19:12 +00:00
Add clean-structure cmd to setup and clean dir structure
This commit is contained in:
parent
77d5b083eb
commit
b7c8dee567
2 changed files with 45 additions and 3 deletions
42
cmds/portmaster-start/dirs.go
Normal file
42
cmds/portmaster-start/dirs.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(cleanStructureCmd)
|
||||
}
|
||||
|
||||
var cleanStructureCmd = &cobra.Command{
|
||||
Use: "clean-structure",
|
||||
Short: "Create and clean the required directory structure",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := ensureLoggingDir(); err != nil {
|
||||
return err
|
||||
}
|
||||
return cleanAndEnsureExecDir()
|
||||
},
|
||||
}
|
||||
|
||||
func cleanAndEnsureExecDir() error {
|
||||
execDir := dataRoot.ChildDir("exec", 0o777)
|
||||
|
||||
// Clean up and remove exec dir.
|
||||
err := os.RemoveAll(execDir.Path)
|
||||
if err != nil {
|
||||
log.Printf("WARNING: failed to fully remove exec dir (%q) for cleaning: %s", execDir.Path, err)
|
||||
}
|
||||
|
||||
// Re-create exec dir.
|
||||
err = execDir.Ensure()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to initialize exec dir (%q): %w", execDir.Path, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -51,7 +51,7 @@ var (
|
|||
return err
|
||||
}
|
||||
|
||||
if err := configureLogging(); err != nil {
|
||||
if err := ensureLoggingDir(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -171,12 +171,12 @@ func configureRegistry(mustLoadIndex bool) error {
|
|||
return updateRegistryIndex(mustLoadIndex)
|
||||
}
|
||||
|
||||
func configureLogging() error {
|
||||
func ensureLoggingDir() error {
|
||||
// set up logs root
|
||||
logsRoot = dataRoot.ChildDir("logs", 0777)
|
||||
err := logsRoot.Ensure()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to initialize logs root: %s", err)
|
||||
return fmt.Errorf("failed to initialize logs root (%q): %s", logsRoot.Path, err)
|
||||
}
|
||||
|
||||
// warn about CTRL-C on windows
|
||||
|
|
Loading…
Add table
Reference in a new issue