code refactor: tidy-up
This commit is contained in:
parent
0ac59c5407
commit
3053c19dd0
3 changed files with 98 additions and 87 deletions
|
|
@ -42,6 +42,28 @@ type (
|
|||
|
||||
const METADATA_FILENAME = "metadata.toml"
|
||||
|
||||
func InitialiseDirectory(directory string) error {
|
||||
dirInfo, err := os.Stat(directory)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return fmt.Errorf("no such directory: %s", directory)
|
||||
}
|
||||
return fmt.Errorf("failed to open directory: %v", err)
|
||||
}
|
||||
if !dirInfo.IsDir() {
|
||||
return fmt.Errorf("not a directory: %s", directory)
|
||||
}
|
||||
|
||||
_, err = os.Stat(path.Join(directory, METADATA_FILENAME))
|
||||
if err == nil {
|
||||
return fmt.Errorf("directory already initialised: %s", directory)
|
||||
}
|
||||
|
||||
err = WriteMetadata(directory, DefaultMetadata())
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func ScanSegments(directory string, extension string) ([]string, error) {
|
||||
entries, err := os.ReadDir(directory)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue