46 lines
840 B
Go
46 lines
840 B
Go
// Copyright 2022 wanderer <a_mirre at utb dot cz>
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package algo
|
|
|
|
import (
|
|
"errors"
|
|
"log"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func sanitiseFName(s string) string {
|
|
return strings.ReplaceAll(s, " ", "_")
|
|
}
|
|
|
|
// createFolder creates a folder at the specified path, if it doesn't already
|
|
// exist.
|
|
func createFolder(path string) error {
|
|
var err error
|
|
|
|
if _, err = os.Stat(path); errors.Is(err, os.ErrNotExist) {
|
|
err = os.Mkdir(path, os.ModePerm)
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
// createPath creates all folders in the provided path, if they don't already
|
|
// exist.
|
|
func createPath(path string) error {
|
|
var err error
|
|
|
|
if _, err = os.Stat(path); errors.Is(err, os.ErrNotExist) {
|
|
err = os.MkdirAll(path, os.ModePerm)
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
}
|
|
|
|
return err
|
|
}
|