repos / pico

pico services mono repo
git clone https://github.com/picosh/pico.git

commit
5fd38b2
parent
1043ee3
author
Eric Bower
date
2025-04-18 13:15:37 -0400 EDT
chore(pobj.fs): provide metadata

fix(pobj.fs): attempt to delete empty folder
1 files changed,  +8, -1
M pkg/pobj/storage/fs.go
+8, -1
 1@@ -5,6 +5,7 @@ import (
 2 	"io"
 3 	"io/fs"
 4 	"log/slog"
 5+	"net/http"
 6 	"os"
 7 	"path"
 8 	"path/filepath"
 9@@ -12,6 +13,7 @@ import (
10 	"time"
11 
12 	"github.com/picosh/pico/pkg/send/utils"
13+	"github.com/picosh/pico/pkg/shared/mime"
14 )
15 
16 // https://stackoverflow.com/a/32482941
17@@ -96,7 +98,7 @@ func (s *StorageFS) DeleteBucket(bucket Bucket) error {
18 func (s *StorageFS) GetObject(bucket Bucket, fpath string) (utils.ReadAndReaderAtCloser, *ObjectInfo, error) {
19 	objInfo := &ObjectInfo{
20 		LastModified: time.Time{},
21-		Metadata:     nil,
22+		Metadata:     make(http.Header),
23 	}
24 
25 	dat, err := os.Open(filepath.Join(bucket.Path, fpath))
26@@ -111,6 +113,7 @@ func (s *StorageFS) GetObject(bucket Bucket, fpath string) (utils.ReadAndReaderA
27 
28 	objInfo.Size = info.Size()
29 	objInfo.LastModified = info.ModTime()
30+	objInfo.Metadata.Set("content-type", mime.GetMimeType(fpath))
31 	return dat, objInfo, nil
32 }
33 
34@@ -147,6 +150,10 @@ func (s *StorageFS) DeleteObject(bucket Bucket, fpath string) error {
35 		return err
36 	}
37 
38+	// try to remove dir if it is empty
39+	dir := filepath.Dir(loc)
40+	_ = os.Remove(dir)
41+
42 	return nil
43 }
44