1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-08-11 17:50:58 +00:00

Merge pull request 'fix(cache-server): use consistent uint64' (#68) from fix/cache/use-uint64 into main

Reviewed-on: https://code.forgejo.org/forgejo/act/pulls/68
Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org>
This commit is contained in:
earl-warren 2024-11-22 06:57:18 +00:00
commit 594fd4ffa3
2 changed files with 10 additions and 10 deletions

View file

@ -227,7 +227,7 @@ func (h *Handler) reserve(w http.ResponseWriter, r *http.Request, _ httprouter.P
// PATCH /_apis/artifactcache/caches/:id // PATCH /_apis/artifactcache/caches/:id
func (h *Handler) upload(w http.ResponseWriter, r *http.Request, params httprouter.Params) { func (h *Handler) upload(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
id, err := strconv.ParseInt(params.ByName("id"), 10, 64) id, err := strconv.ParseUint(params.ByName("id"), 10, 64)
if err != nil { if err != nil {
h.responseJSON(w, r, 400, err) h.responseJSON(w, r, 400, err)
return return
@ -268,7 +268,7 @@ func (h *Handler) upload(w http.ResponseWriter, r *http.Request, params httprout
// POST /_apis/artifactcache/caches/:id // POST /_apis/artifactcache/caches/:id
func (h *Handler) commit(w http.ResponseWriter, r *http.Request, params httprouter.Params) { func (h *Handler) commit(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
id, err := strconv.ParseInt(params.ByName("id"), 10, 64) id, err := strconv.ParseUint(params.ByName("id"), 10, 64)
if err != nil { if err != nil {
h.responseJSON(w, r, 400, err) h.responseJSON(w, r, 400, err)
return return
@ -323,13 +323,13 @@ func (h *Handler) commit(w http.ResponseWriter, r *http.Request, params httprout
// GET /_apis/artifactcache/artifacts/:id // GET /_apis/artifactcache/artifacts/:id
func (h *Handler) get(w http.ResponseWriter, r *http.Request, params httprouter.Params) { func (h *Handler) get(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
id, err := strconv.ParseInt(params.ByName("id"), 10, 64) id, err := strconv.ParseUint(params.ByName("id"), 10, 64)
if err != nil { if err != nil {
h.responseJSON(w, r, 400, err) h.responseJSON(w, r, 400, err)
return return
} }
h.useCache(id) h.useCache(id)
h.storage.Serve(w, r, uint64(id)) h.storage.Serve(w, r, id)
} }
// POST /_apis/artifactcache/clean // POST /_apis/artifactcache/clean
@ -394,7 +394,7 @@ func insertCache(db *bolthold.Store, cache *Cache) error {
return nil return nil
} }
func (h *Handler) useCache(id int64) { func (h *Handler) useCache(id uint64) {
db, err := h.openDB() db, err := h.openDB()
if err != nil { if err != nil {
return return
@ -539,16 +539,16 @@ func (h *Handler) responseJSON(w http.ResponseWriter, r *http.Request, code int,
_, _ = w.Write(data) _, _ = w.Write(data)
} }
func parseContentRange(s string) (int64, int64, error) { func parseContentRange(s string) (uint64, uint64, error) {
// support the format like "bytes 11-22/*" only // support the format like "bytes 11-22/*" only
s, _, _ = strings.Cut(strings.TrimPrefix(s, "bytes "), "/") s, _, _ = strings.Cut(strings.TrimPrefix(s, "bytes "), "/")
s1, s2, _ := strings.Cut(s, "-") s1, s2, _ := strings.Cut(s, "-")
start, err := strconv.ParseInt(s1, 10, 64) start, err := strconv.ParseUint(s1, 10, 64)
if err != nil { if err != nil {
return 0, 0, fmt.Errorf("parse %q: %w", s, err) return 0, 0, fmt.Errorf("parse %q: %w", s, err)
} }
stop, err := strconv.ParseInt(s2, 10, 64) stop, err := strconv.ParseUint(s2, 10, 64)
if err != nil { if err != nil {
return 0, 0, fmt.Errorf("parse %q: %w", s, err) return 0, 0, fmt.Errorf("parse %q: %w", s, err)
} }

View file

@ -31,7 +31,7 @@ func (s *Storage) Exist(id uint64) (bool, error) {
return true, nil return true, nil
} }
func (s *Storage) Write(id uint64, offset int64, reader io.Reader) error { func (s *Storage) Write(id uint64, offset uint64, reader io.Reader) error {
name := s.tempName(id, offset) name := s.tempName(id, offset)
if err := os.MkdirAll(filepath.Dir(name), 0o755); err != nil { if err := os.MkdirAll(filepath.Dir(name), 0o755); err != nil {
return err return err
@ -110,7 +110,7 @@ func (s *Storage) tempDir(id uint64) string {
return filepath.Join(s.rootDir, "tmp", fmt.Sprint(id)) return filepath.Join(s.rootDir, "tmp", fmt.Sprint(id))
} }
func (s *Storage) tempName(id uint64, offset int64) string { func (s *Storage) tempName(id uint64, offset uint64) string {
return filepath.Join(s.tempDir(id), fmt.Sprintf("%016x", offset)) return filepath.Join(s.tempDir(id), fmt.Sprintf("%016x", offset))
} }