- commit
- f502452
- parent
- 3a18c6d
- author
- Eric Bower
- date
- 2023-08-14 02:57:44 +0000 UTC
chore: cleanup
2 files changed,
+15,
-9
+4,
-1
1@@ -1196,6 +1196,8 @@ func (me *PsqlDB) LinkToProject(userID, projectID, projectDir string) error {
2 if err != nil {
3 return err
4 }
5+ isAlreadyLinked := linkToProject.Name != linkToProject.ProjectDir
6+ sameProject := linkToProject.ID == projectID
7
8 /*
9 A project linked to another project which is also linked to a
10@@ -1213,7 +1215,7 @@ func (me *PsqlDB) LinkToProject(userID, projectID, projectDir string) error {
11 We ensure that `project.Name` and `project.ProjectDir` are identical
12 when there is no aliasing.
13 */
14- if linkToProject.Name != linkToProject.ProjectDir {
15+ if !sameProject && isAlreadyLinked {
16 return fmt.Errorf(
17 "cannot link (%s) to (%s) because it is also a link to (%s)",
18 projectID,
19@@ -1230,6 +1232,7 @@ func (me *PsqlDB) LinkToProject(userID, projectID, projectDir string) error {
20 )
21 return err
22 }
23+
24 func (me *PsqlDB) RemoveProject(projectID string) error {
25 _, err := me.Db.Exec(sqlRemoveProject, projectID)
26 return err
+11,
-8
1@@ -33,16 +33,19 @@ func getUser(s ssh.Session, dbpool db.DB) (*db.User, error) {
2 }
3
4 func getHelpText(userName, projectName string) string {
5- helpStr := "commands: [rm, list, link, unlink]\n\n"
6+ helpStr := "commands: [help, stats, ls, rm, clean, link, links, unlink]\n\n"
7 sshCmdStr := fmt.Sprintf("ssh %s@pgs.sh", userName)
8 helpStr += fmt.Sprintf("`%s help`: prints this screen\n", sshCmdStr)
9 helpStr += fmt.Sprintf("`%s stats`: prints stats for user\n", sshCmdStr)
10 helpStr += fmt.Sprintf("`%s ls`: lists projects\n", sshCmdStr)
11 helpStr += fmt.Sprintf("`%s %s rm`: deletes `%s`\n", sshCmdStr, projectName, projectName)
12- helpStr += fmt.Sprintf("`%s %s clean`: removes all projects that matches `%s` which is not linked\n", sshCmdStr, projectName, projectName)
13+ helpStr += fmt.Sprintf("`%s %s clean`: removes all projects that match prefix `%s` and is not linked to another project\n", sshCmdStr, projectName, projectName)
14 helpStr += fmt.Sprintf("`%s %s links`: lists all projects linked to `%s`\n", sshCmdStr, projectName, projectName)
15- helpStr += fmt.Sprintf("`%s %s link projectB`: symbolic link from `%s` to `projectB`\n", sshCmdStr, projectName, projectName)
16- helpStr += fmt.Sprintf("`%s %s unlink`: removes symbolic link for `%s`\n", sshCmdStr, projectName, projectName)
17+ helpStr += fmt.Sprintf("`%s %s link project-b`: symbolic link from `%s` to `project-b`\n", sshCmdStr, projectName, projectName)
18+ helpStr += fmt.Sprintf(
19+ "`%s %s unlink`: alias for `%s link %s`, which removes symbolic link for `%s`\n",
20+ sshCmdStr, projectName, projectName, projectName, projectName,
21+ )
22 return helpStr
23 }
24
25@@ -71,7 +74,7 @@ func WishMiddleware(handler *uploadassets.UploadAssetHandler) wish.Middleware {
26 if len(args) == 1 {
27 cmd := strings.TrimSpace(args[0])
28 if cmd == "help" {
29- _, _ = session.Write([]byte(getHelpText(user.Name, "projectA")))
30+ _, _ = session.Write([]byte(getHelpText(user.Name, "project-a")))
31 } else if cmd == "stats" {
32 bucketName := shared.GetAssetBucketName(user.ID)
33 bucket, err := store.UpsertBucket(bucketName)
34@@ -149,7 +152,7 @@ func WishMiddleware(handler *uploadassets.UploadAssetHandler) wish.Middleware {
35 utils.ErrorHandler(session, fmt.Errorf("project (%s) does not exit", projectName))
36 return
37 }
38- err = dbpool.RemoveProject(project.ID)
39+ err = dbpool.LinkToProject(user.ID, project.ID, project.Name)
40 if err != nil {
41 log.Error(err)
42 utils.ErrorHandler(session, err)
43@@ -256,7 +259,7 @@ func WishMiddleware(handler *uploadassets.UploadAssetHandler) wish.Middleware {
44 }
45
46 if len(links) == 0 {
47- out := fmt.Sprintf("project (%s) is available to delete", project.Name)
48+ out := fmt.Sprintf("project (%s) is available to delete\n", project.Name)
49 _, _ = session.Write([]byte(out))
50 rmProjects = append(rmProjects, project)
51 }
52@@ -272,7 +275,7 @@ func WishMiddleware(handler *uploadassets.UploadAssetHandler) wish.Middleware {
53 for _, file := range fileList {
54 err = store.DeleteFile(bucket, file.Name())
55 if err == nil {
56- // _, _ = session.Write([]byte(fmt.Sprintf("deleted (%s)\n", file.Name())))
57+ _, _ = session.Write([]byte(fmt.Sprintf("deleted (%s)\n", file.Name())))
58 } else {
59 log.Error(err)
60 utils.ErrorHandler(session, err)