Skip to content

Commit

Permalink
Update file.go
Browse files Browse the repository at this point in the history
  • Loading branch information
ayhan-dev authored Aug 29, 2023
1 parent c2f158a commit 9e9e02b
Showing 1 changed file with 28 additions and 41 deletions.
69 changes: 28 additions & 41 deletions internal/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,49 +71,36 @@ func CreateHostOutputFolder(host string) {
// already exists, if yes asks the user if cariddi has to overwrite it;
// if no cariddi creates it.
// Whenever an instruction fails, it exits with an error message.
func CreateOutputFile(target string, subcommand string, format string) string {
target = ReplaceBadCharacterOutput(target)

var filename string
if subcommand != "" {
filename = filepath.Join("output-cariddi", target+"."+subcommand+"."+format)
} else {
filename = filepath.Join("output-cariddi", target+"."+format)
}

_, err := os.Stat(filename)

if os.IsNotExist(err) {
if _, err := os.Stat("output-cariddi/"); os.IsNotExist(err) {
CreateOutputFolder()
}
// If the file doesn't exist, create it.
f, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY, Permission0644)
if err != nil {
fmt.Println("Can't create output file.")
os.Exit(1)
}

f.Close()
} else {
// The file already exists, overwrite.

f, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY, Permission0644)
if err != nil {
fmt.Println("Can't create output file.")
os.Exit(1)
}
err = f.Truncate(0)
if err != nil {
fmt.Println("Can't create output file.")
os.Exit(1)
}
f.Close()
}

return filename
func CreateOutputFile(target string, subcommand string, format string) string {
target = ReplaceBadCharacterOutput(target)

filename := filepath.Join("output-cariddi", target)
if subcommand != "" {
filename += "." + subcommand
}
filename += "." + format

Check failure on line 82 in internal/file/file.go

View workflow job for this annotation

GitHub Actions / lint

assignments should only be cuddled with other assignments (wsl)

if _, err := os.Stat(filename); os.IsNotExist(err) {
CreateOutputFolder()

f, err := os.Create(filename)
if err != nil {
fmt.Println("Can't create output file.")
os.Exit(1)
}
f.Close()

Check failure on line 92 in internal/file/file.go

View workflow job for this annotation

GitHub Actions / lint

expressions should not be cuddled with blocks (wsl)
} else {
f, err := os.OpenFile(filename, os.O_TRUNC|os.O_WRONLY, Permission0644)
if err != nil {
fmt.Println("Can't create output file.")
os.Exit(1)
}
f.Close()
}

return filename
}

// CreateIndexOutputFile takes as input the name of the index file.
// It creates the output folder if needed, then checks if the index output file
// already exists, if no cariddi creates it.
Expand Down

0 comments on commit 9e9e02b

Please sign in to comment.