From 6949c8ab4eff9e02ac24e497f3b02d6a65a03c68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Thu, 20 Jun 2024 11:38:00 -0700 Subject: [PATCH] make sure trash directories exist --- main.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/main.go b/main.go index f649049..81a3743 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "bytes" "fmt" + "io/fs" "os" "path/filepath" "slices" @@ -54,6 +55,7 @@ var ( } } + // read the term height and width for tables w, h, e := term.GetSize(int(os.Stdout.Fd())) if e != nil { w = 80 @@ -62,6 +64,23 @@ var ( termwidth = w 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 }