Skip to content

Commit

Permalink
fix: run mkdir with optional sudo is can't create dir
Browse files Browse the repository at this point in the history
  • Loading branch information
femnad committed Jan 25, 2024
1 parent e80f7f2 commit 6fb7c2c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion common/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package common
import (
"bufio"
"fmt"
"github.com/femnad/fup/internal"
"os"
"path"

"github.com/femnad/fup/internal"
)

const permissions = 0o600
Expand Down
22 changes: 14 additions & 8 deletions internal/dir.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package internal

import "os"
import (
"fmt"
"os"
)

func EnsureDirAbsent(dir string) error {
_, err := os.Stat(dir)
Expand All @@ -14,14 +17,17 @@ func EnsureDirAbsent(dir string) error {

func EnsureDirExists(dir string) error {
_, err := os.Stat(dir)
if os.IsNotExist(err) {
err = os.MkdirAll(dir, 0744)
if err != nil {
return err
}
} else if err != nil {
if err == nil {
return nil
}

if !os.IsNotExist(err) {
return err
}

return nil
err = os.MkdirAll(dir, 0744)
if os.IsPermission(err) {
return MaybeRunWithSudo(fmt.Sprintf("mkdir %s", dir))
}
return err
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

const (
version = "0.31.1"
version = "0.31.2"
)

type args struct {
Expand Down

0 comments on commit 6fb7c2c

Please sign in to comment.