~gitpocket/gitpocket

1

fix(web): clone failures, internal errors and stale sessions

commit
ff1bef987ecef51d6a27bb2709c291418fbc4a0d browse tree
parent
51ac7092f52ff581406afe3fa76e2e04b8dd941c
author
obscurejames <354576047+obscurejames@users.noreply.github.com>
signature
Verified ~james signed with a key registered by ~james
date
2026-11-02 21:01 UTC

4 files changed, +25 −13

pull.go modified

@@ -4,6 +4,7 @@ import (
44 "database/sql"
55 "errors"
66 "fmt"
7+ "log"
78 "html/template"
89 "net/http"
910 "os"
@@ -828,12 +829,15 @@ func (s *Server) fork(w http.ResponseWriter, r *http.Request, repo Repo) {
828829 return
829830 }
830831 dir := s.repoDir(fork)
831- if err := os.MkdirAll(filepath.Dir(dir), 0o755); err == nil {
832+ err = os.MkdirAll(filepath.Dir(dir), 0o755)
833+ if err == nil {
832834 err = cloneRepo(s.repoDir(repo), dir)
833835 }
834836 if err != nil {
837+ log.Printf("create %s: %v", fork.Path(), err)
838+ os.RemoveAll(dir)
835839 s.store.DeleteRepo(fork.ID)
836- s.fail(w, r, 500, err.Error())
840+ s.fail(w, r, 500, "Could not create the repository")
837841 return
838842 }
839843 installHook(s.root, dir)

static/style.css modified

@@ -190,9 +190,9 @@ input[type=file]{border:0;padding:0}
190190 .twocol{display:grid;grid-template-columns:1fr 1fr;gap:2rem;margin-bottom:2rem}
191191 .twocol label{display:flex;flex-direction:column;gap:.25rem;margin-bottom:.8rem}
192192 .twocol .legend{display:block;margin-bottom:.4rem}
193-label.radio,.twocol label.check,.modes label.radio{flex-direction:row;flex-wrap:wrap;align-items:center;gap:.4rem;margin-bottom:.6rem}
194-label.radio small,.modes label.radio small{flex-basis:100%;color:var(--muted);padding-left:1.4rem}
195-.modes input[type=radio]{width:auto;margin:0}
193+label.radio,.twocol label.check{flex-direction:row;flex-wrap:wrap;align-items:center;gap:.4rem;margin-bottom:.6rem}
194+label.radio small{flex-basis:100%;color:var(--muted);padding-left:1.4rem}
195+label.radio input[type=radio]{width:auto;margin:0}
196196 h3.plain{border:0;font-size:1.25rem}
197197 .columns.browse{grid-template-columns:minmax(0,2fr) 1fr}
198198 .search input[name=search],.search input[name=q]{width:100%}

store.go modified

@@ -404,6 +404,10 @@ func (s *Store) DeleteSession(id string) {
404404 s.db.Exec(`delete from sessions where id = ?`, id)
405405 }
406406
407+func (s *Store) KeepOnlySession(user int64, id string) {
408+ s.db.Exec(`delete from sessions where user = ? and id != ?`, user, id)
409+}
410+
407411 func (s *Store) DeleteSessions(user int64) {
408412 s.db.Exec(`delete from sessions where user = ?`, user)
409413 }
@@ -1050,12 +1054,6 @@ func (s *Store) Starred(user, repo int64) bool {
10501054 return n > 0
10511055 }
10521056
1053-func (s *Store) StarCount(repo int64) int {
1054- var n int
1055- s.db.QueryRow(`select count(*) from stars where repo = ?`, repo).Scan(&n)
1056- return n
1057-}
1058-
10591057 func (s *Store) StarredCount(user int64) int {
10601058 var n int
10611059 s.db.QueryRow(`select count(*) from stars st join repos r on r.id = st.repo where st.user = ? and r.private = 0`, user).Scan(&n)

web.go modified

@@ -198,6 +198,10 @@ func (s *Server) render(w http.ResponseWriter, r *http.Request, name string, p p
198198 }
199199
200200 func (s *Server) fail(w http.ResponseWriter, r *http.Request, code int, msg string) {
201+ if code >= 500 {
202+ log.Printf("%s %s: %s", r.Method, r.URL.Path, msg)
203+ msg = "Something went wrong"
204+ }
201205 w.WriteHeader(code)
202206 s.render(w, r, "error", page{Title: msg, Error: msg})
203207 }
@@ -437,12 +441,15 @@ func (s *Server) create(w http.ResponseWriter, r *http.Request) {
437441 return
438442 }
439443 dir := s.repoDir(repo)
440- if err := os.MkdirAll(filepath.Dir(dir), 0o755); err == nil {
444+ err = os.MkdirAll(filepath.Dir(dir), 0o755)
445+ if err == nil {
441446 err = initRepo(dir)
442447 }
443448 if err != nil {
449+ log.Printf("create %s: %v", repo.Path(), err)
450+ os.RemoveAll(dir)
444451 s.store.DeleteRepo(repo.ID)
445- s.fail(w, r, 500, err.Error())
452+ s.fail(w, r, 500, "Could not create the repository")
446453 return
447454 }
448455 installHook(s.root, dir)
@@ -819,6 +826,9 @@ func (s *Server) password(w http.ResponseWriter, r *http.Request) {
819826 http.Redirect(w, r, "/settings/security?error="+template.URLQueryEscaper(err.Error()), http.StatusSeeOther)
820827 return
821828 }
829+ if c, err := r.Cookie("session"); err == nil {
830+ s.store.KeepOnlySession(u.ID, c.Value)
831+ }
822832 http.Redirect(w, r, "/settings/security", http.StatusSeeOther)
823833 }
824834