Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions directories_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package koii

import (
"fmt"
"os"
"path/filepath"
)

// CreateDirectory creates a new directory at the specified path
//
29 changes: 29 additions & 0 deletions utilities.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
```go
package utilities

import (
"fmt"
"path/filepath"
"strings"

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/gocarina/gocsv"
)

// CreateDirectory creates a new directory with the given path
func CreateDirectory(path string, perm uint32) error {
path, err := filepath.Abs(path)
if err != nil {
return fmt.Errorf("failed to normalize path: %w", err)
}

if _, err := os.Stat(path); err == nil {
return fmt.Errorf("directory already exists")
} else if !os.IsNotExist(err) {
return fmt.Errorf("failed to check if directory exists: %w", err)
}

err = os.MkdirAll(path, perm)
if err != nil {