- commit
- e5109c2
- parent
- 4d12bdf
- author
- Eric Bower
- date
- 2023-11-12 01:13:02 +0000 UTC
fix(pgs): missing project name when deleting project files from store
5 files changed,
+23,
-11
M
Makefile
+4,
-1
1@@ -82,8 +82,11 @@ pgs-site:
2 cp ./pgs/public/* ./public
3 .PHONY: pgs-site
4
5+pgs-dev: pgs-static pgs-site
6+ rsync -rv -e "ssh -p 2222" ./public/ erock@localhost:/pgs-local
7+.PHONY: pgs-dev
8+
9 pgs-deploy: pgs-static pgs-site
10- # rsync -rv -e "ssh -p 2222" ./public/ erock@localhost:/pgs-local
11 rsync -rv ./public/ hey@pgs.sh:/pgs-local
12 ssh hey@pgs.sh link pgs-prod pgs-local --write
13 .PHONY: pgs-site-deploy
M
db/db.go
+1,
-0
1@@ -38,6 +38,7 @@ type Project struct {
2 ProjectDir string `json:"project_dir"`
3 Username string `json:"username"`
4 CreatedAt *time.Time `json:"created_at"`
5+ UpdatedAt *time.Time `json:"updated_at"`
6 }
7
8 // Make the Attrs struct implement the driver.Valuer interface. This method
+5,
-3
1@@ -263,9 +263,9 @@ const (
2 LEFT JOIN app_users ON app_users.id = projects.user_id
3 ORDER BY created_at ASC
4 LIMIT $1 OFFSET $2`
5- sqlFindProjectsByUser = `SELECT id, user_id, name, project_dir FROM projects WHERE user_id = $1 ORDER BY name ASC;`
6- sqlFindProjectsByPrefix = `SELECT id, user_id, name, project_dir FROM projects WHERE user_id = $1 AND name = project_dir AND name ILIKE $2 ORDER BY updated_at ASC, name ASC;`
7- sqlFindProjectLinks = `SELECT id, user_id, name, project_dir FROM projects WHERE user_id = $1 AND name != project_dir AND project_dir = $2 ORDER BY name ASC;`
8+ sqlFindProjectsByUser = `SELECT id, user_id, name, project_dir, created_at, updated_at FROM projects WHERE user_id = $1 ORDER BY updated_at DESC;`
9+ sqlFindProjectsByPrefix = `SELECT id, user_id, name, project_dir, created_at, updated_at FROM projects WHERE user_id = $1 AND name = project_dir AND name ILIKE $2 ORDER BY updated_at ASC, name ASC;`
10+ sqlFindProjectLinks = `SELECT id, user_id, name, project_dir, created_at, updated_at FROM projects WHERE user_id = $1 AND name != project_dir AND project_dir = $2 ORDER BY name ASC;`
11 sqlLinkToProject = `UPDATE projects SET project_dir = $1, updated_at = $2 WHERE id = $3;`
12 sqlRemoveProject = `DELETE FROM projects WHERE id = $1;`
13 )
14@@ -1365,6 +1365,8 @@ func (me *PsqlDB) FindProjectsByUser(userID string) ([]*db.Project, error) {
15 &project.UserID,
16 &project.Name,
17 &project.ProjectDir,
18+ &project.CreatedAt,
19+ &project.UpdatedAt,
20 )
21 if err != nil {
22 return nil, err
+12,
-2
1@@ -3,6 +3,7 @@ package pgs
2 import (
3 "errors"
4 "fmt"
5+ "path/filepath"
6
7 "github.com/charmbracelet/ssh"
8 "github.com/picosh/pico/db"
9@@ -80,8 +81,17 @@ func (c *Cmd) rmProjectAssets(projectName string) error {
10
11 for _, file := range fileList {
12 intent := fmt.Sprintf("deleted (%s)", file.Name())
13+ c.log.Infof(
14+ "(%s) attempting to delete (bucket: %s) (%s)",
15+ c.user.Name,
16+ bucket.Name,
17+ file.Name(),
18+ )
19 if c.write {
20- err = c.store.DeleteFile(bucket, file.Name())
21+ err = c.store.DeleteFile(
22+ bucket,
23+ filepath.Join(projectName, file.Name()),
24+ )
25 if err == nil {
26 c.output(intent)
27 } else {
28@@ -142,7 +152,7 @@ func (c *Cmd) ls() error {
29 for _, project := range projects {
30 out := fmt.Sprintf("%s (links to: %s)", project.Name, project.ProjectDir)
31 if project.Name == project.ProjectDir {
32- out = project.Name
33+ out = fmt.Sprintf("%s\t(last updated: %s)", project.Name, project.UpdatedAt)
34 }
35 c.output(out)
36 }
1@@ -180,9 +180,5 @@ func (s *StorageMinio) PutFile(bucket Bucket, fpath string, contents utils.Reade
2
3 func (s *StorageMinio) DeleteFile(bucket Bucket, fpath string) error {
4 err := s.Client.RemoveObject(context.TODO(), bucket.Name, fpath, minio.RemoveObjectOptions{})
5- if err != nil {
6- return err
7- }
8-
9- return nil
10+ return err
11 }