fix: issue with creating author file from scratch. Fixed file permissions

This commit is contained in:
Slug-Boi
2025-01-13 15:22:19 +01:00
parent a15067a013
commit 0e47a9336a
+9 -10
View File
@@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"os" "os"
"regexp" "regexp"
"strings"
) )
// Author file utils is a package that contains functions that are used to read // Author file utils is a package that contains functions that are used to read
@@ -26,6 +27,7 @@ func Find_authorfile() string {
} }
func CheckAuthorFile() string { func CheckAuthorFile() string {
var cocommit_folder string
authorfile := Find_authorfile() authorfile := Find_authorfile()
if _, err := os.Stat(authorfile); os.IsNotExist(err) { if _, err := os.Stat(authorfile); os.IsNotExist(err) {
println("Author file not found at: ", authorfile) println("Author file not found at: ", authorfile)
@@ -36,18 +38,15 @@ func CheckAuthorFile() string {
println("Error reading response") println("Error reading response")
} }
if response == "y" { if response == "y" {
if authorfile == "" { parts := strings.Split(authorfile, "/")
fmt.Println("author_file environment variable not set using default location:") cocommit_folder = strings.Join(parts[:len(parts)-1], "/")
config, err := os.UserConfigDir()
if err != nil {
fmt.Println("Error getting user config directory")
os.Exit(1)
}
authorfile = config + "/cocommit/authors"
fmt.Println(authorfile)
}
// create the author file // create the author file
err := os.Mkdir(cocommit_folder, 0766)
if err != nil {
fmt.Println("Error creating directory: ", err, cocommit_folder)
os.Exit(1)
}
file, err := os.Create(authorfile) file, err := os.Create(authorfile)
if err != nil { if err != nil {
fmt.Println("Error creating file: ", err) fmt.Println("Error creating file: ", err)