make sure trash directories exist

This commit is contained in:
Lilian Jónsdóttir 2024-06-20 11:38:00 -07:00
parent 7b4751c1ae
commit 6949c8ab4e

19
main.go
View file

@ -3,6 +3,7 @@ package main
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/fs"
"os" "os"
"path/filepath" "path/filepath"
"slices" "slices"
@ -54,6 +55,7 @@ var (
} }
} }
// read the term height and width for tables
w, h, e := term.GetSize(int(os.Stdout.Fd())) w, h, e := term.GetSize(int(os.Stdout.Fd()))
if e != nil { if e != nil {
w = 80 w = 80
@ -62,6 +64,23 @@ var (
termwidth = w termwidth = w
termheight = h termheight = h
// ensure trash directories exist
if _, e := os.Stat(trashDir); os.IsNotExist(e) {
if err := os.Mkdir(trashDir, fs.FileMode(0755)); err != nil {
return err
}
}
if _, e := os.Stat(filepath.Join(trashDir, "info")); os.IsNotExist(e) {
if err := os.Mkdir(filepath.Join(trashDir, "info"), fs.FileMode(0755)); err != nil {
return err
}
}
if _, e := os.Stat(filepath.Join(trashDir, "files")); os.IsNotExist(e) {
if err := os.Mkdir(filepath.Join(trashDir, "files"), fs.FileMode(0755)); err != nil {
return err
}
}
return return
} }