Skip to content

Commit

Permalink
fix: ensure log dir is created
Browse files Browse the repository at this point in the history
  • Loading branch information
nixpig committed Feb 2, 2025
1 parent 60923a5 commit 86a00f0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 4 additions & 0 deletions internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cli
import (
"fmt"
"os"
"path/filepath"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -21,6 +22,9 @@ func RootCmd() *cobra.Command {
PersistentPreRun: func(cmd *cobra.Command, args []string) {
logfile, _ := cmd.Flags().GetString("log")
if _, err := os.Stat(logfile); os.IsNotExist(err) {
if err := os.MkdirAll(filepath.Dir(logfile), os.ModeDir); err != nil {
fmt.Printf("Warning: failed to create log directory %s.\n", logfile)
}
f, err := os.Create(logfile)
if err != nil && !os.IsExist(err) {
fmt.Printf("Warning: failed to create log file %s.\n", logfile)
Expand Down
2 changes: 0 additions & 2 deletions internal/cli/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"

"github.com/nixpig/anocir/internal/operations"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -29,7 +28,6 @@ func stateCmd() *cobra.Command {
if _, err := cmd.OutOrStdout().Write(
[]byte(state),
); err != nil {
logrus.Errorf("state operation failed: %s", err)
return fmt.Errorf("write state to stdout: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ func (c *Container) Reexec() error {

containerConn, err := listener.Accept()
if err != nil {
logrus.Errorf("☠️ accept on container socket: %s", err)
logrus.Errorf("failed to accept on container socket: %s", err)
return fmt.Errorf("accept on container sock: %w", err)
}

Expand Down

0 comments on commit 86a00f0

Please sign in to comment.