repos / pico

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

commit
e28e5d4
parent
d01276a
author
Eric Bower
date
2025-06-22 14:53:04 -0400 EDT
fix(pgs): fs adapter updates
3 files changed,  +45, -27
M pkg/apps/pgs/cli.go
+3, -0
 1@@ -102,6 +102,9 @@ func (c *Cmd) RmProjectAssets(projectName string) error {
 2 	c.output(fmt.Sprintf("found (%d) assets for project (%s), removing", len(fileList), projectName))
 3 
 4 	for _, file := range fileList {
 5+		if file.IsDir() {
 6+			continue
 7+		}
 8 		intent := fmt.Sprintf("deleted (%s)", file.Name())
 9 		c.Log.Info(
10 			"attempting to delete file",
M pkg/pobj/storage/fs.go
+36, -17
 1@@ -185,10 +185,15 @@ func (s *StorageFS) DeleteObject(bucket Bucket, fpath string) error {
 2 	for dir != "" {
 3 		err = os.Remove(dir)
 4 		if err != nil {
 5+			s.Logger.Info("removing dir", "dir", dir, "err", err)
 6 			break
 7 		}
 8 		fp := strings.Split(dir, "/")
 9-		dir = "/" + filepath.Join(fp[:len(fp)-1]...)
10+		prefix := ""
11+		if strings.HasPrefix(loc, "/") {
12+			prefix = "/"
13+		}
14+		dir = prefix + filepath.Join(fp[:len(fp)-1]...)
15 	}
16 
17 	return nil
18@@ -234,14 +239,27 @@ func (s *StorageFS) ListObjects(bucket Bucket, dir string, recursive bool) ([]os
19 		return fileList, err
20 	}
21 
22-	var files []fs.DirEntry
23+	var files []utils.VirtualFile
24 
25 	if recursive {
26 		err = filepath.WalkDir(fpath, func(s string, d fs.DirEntry, err error) error {
27 			if err != nil {
28 				return err
29 			}
30-			files = append(files, d)
31+			info, err := d.Info()
32+			if err != nil {
33+				return nil
34+			}
35+			fname := strings.TrimPrefix(s, fpath)
36+			if fname == "" {
37+				return nil
38+			}
39+			files = append(files, utils.VirtualFile{
40+				FName:    fname,
41+				FIsDir:   info.IsDir(),
42+				FSize:    info.Size(),
43+				FModTime: info.ModTime(),
44+			})
45 			return nil
46 		})
47 		if err != nil {
48@@ -249,27 +267,28 @@ func (s *StorageFS) ListObjects(bucket Bucket, dir string, recursive bool) ([]os
49 			return fileList, nil
50 		}
51 	} else {
52-		files, err = os.ReadDir(fpath)
53+		fls, err := os.ReadDir(fpath)
54 		if err != nil {
55 			fileList = append(fileList, info)
56 			return fileList, nil
57 		}
58+		for _, d := range fls {
59+			info, err := d.Info()
60+			if err != nil {
61+				continue
62+			}
63+			fp := info.Name()
64+			files = append(files, utils.VirtualFile{
65+				FName:    fp,
66+				FIsDir:   info.IsDir(),
67+				FSize:    info.Size(),
68+				FModTime: info.ModTime(),
69+			})
70+		}
71 	}
72 
73 	for _, f := range files {
74-		info, err := f.Info()
75-		if err != nil {
76-			return fileList, err
77-		}
78-
79-		i := &utils.VirtualFile{
80-			FName:    f.Name(),
81-			FIsDir:   f.IsDir(),
82-			FSize:    info.Size(),
83-			FModTime: info.ModTime(),
84-		}
85-
86-		fileList = append(fileList, i)
87+		fileList = append(fileList, &f)
88 	}
89 
90 	return fileList, err
M pkg/shared/storage/fs_test.go
+6, -10
 1@@ -113,27 +113,23 @@ func TestFsAdapter(t *testing.T) {
 2 
 3 	expectedObjs := []fs.FileInfo{
 4 		&utils.VirtualFile{
 5-			FName:  "main",
 6+			FName:  "/here",
 7 			FIsDir: true,
 8 		},
 9 		&utils.VirtualFile{
10-			FName:  "here",
11+			FName:  "/here/we",
12 			FIsDir: true,
13 		},
14 		&utils.VirtualFile{
15-			FName:  "we",
16+			FName:  "/here/we/go",
17 			FIsDir: true,
18 		},
19+		&utils.VirtualFile{FName: "/here/we/go/again.txt", FSize: 25},
20 		&utils.VirtualFile{
21-			FName:  "go",
22+			FName:  "/nice",
23 			FIsDir: true,
24 		},
25-		&utils.VirtualFile{FName: "again.txt", FSize: 25},
26-		&utils.VirtualFile{
27-			FName:  "nice",
28-			FIsDir: true,
29-		},
30-		&utils.VirtualFile{FName: "test.txt", FSize: 19},
31+		&utils.VirtualFile{FName: "/nice/test.txt", FSize: 19},
32 	}
33 	ignore := cmpopts.IgnoreFields(utils.VirtualFile{}, "FModTime", "FSize")
34 	if cmp.Equal(objs, expectedObjs, ignore) == false {