Commit 9007322

Eric Bower  ·  2026-10-12 13:24:52 -0400 EDT
parent 2e0e17e
fix(pgs): reject directories during GetObject calls

We were previously relying on the etag computation via io.Copy to implicitly
reject directories.
3 files changed,  +11, -1
+6, -0
......@@ -106,6 +106,12 @@ func TestStorageConformance(t *testing.T) {
106106 if _, _, err := st.GetObject(b, "/proj/missing.txt"); err == nil {
107107 t.Fatal("missing object returned no error")
108108 }
109+
110+ for _, dir := range []string{"/proj/css", "/proj/css/"} {
111+ if _, _, err := st.GetObject(b, dir); !errors.Is(err, fs.ErrNotExist) {
112+ t.Errorf("GetObject(%q) returned %v, want fs.ErrNotExist", dir, err)
113+ }
114+ }
109115 })
110116
111117 t.Run("stat", func(t *testing.T) {
+4, -0
......@@ -122,6 +122,10 @@ func (s *StorageFS) GetObject(bucket Bucket, fpath string) (utils.ReadAndReaderA
122122 _ = dat.Close()
123123 return nil, objInfo, err
124124 }
125+ if info.IsDir() {
126+ _ = dat.Close()
127+ return nil, objInfo, fmt.Errorf("%s is a directory: %w", fpath, fs.ErrNotExist)
128+ }
125129 fillObjectInfo(objInfo, info)
126130 return dat, objInfo, nil
127131 }
+1, -1
......@@ -129,7 +129,7 @@ func (s *StorageMemory) GetObject(bucket Bucket, fpath string) (utils.ReadAndRea
129129
130130 dat, ok := s.storage[bucket.Path][fpath]
131131 if !ok || strings.HasSuffix(fpath, "/") {
132- return nil, objInfo, fmt.Errorf("object does not exist: %s", fpath)
132+ return nil, objInfo, fmt.Errorf("object does not exist: %s: %w", fpath, fs.ErrNotExist)
133133 }
134134
135135 objInfo.Size = int64(len([]byte(dat)))