fix: restore missing blob file when re-publishing a package (#39239)

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Huang-404-Q
2026-09-05 10:33:36 +02:00
committed by GitHub
co-authored by wxiaoguang
parent e4455fb494
commit efa69e7230
10 changed files with 145 additions and 76 deletions
+12 -5
View File
@@ -4,11 +4,14 @@
package packages
import (
"errors"
"io"
"io/fs"
"net/url"
"path"
"strings"
"gitea.dev/modules/optional"
"gitea.dev/modules/setting"
"gitea.dev/modules/storage"
"gitea.dev/modules/util"
@@ -40,11 +43,15 @@ func (s *ContentStore) GetServeDirectURL(key BlobHash256Key, filename, method st
return s.store.ServeDirectURL(KeyToRelativePath(key), filename, method, reqParams)
}
// FIXME: Workaround to be removed in v1.20
// https://github.com/go-gitea/gitea/issues/19586
func (s *ContentStore) Has(key BlobHash256Key) error {
_, err := s.store.Stat(KeyToRelativePath(key))
return err
func (s *ContentStore) OptionalSize(key BlobHash256Key) (sz optional.Option[int64], _ error) {
st, err := s.store.Stat(KeyToRelativePath(key))
if errors.Is(err, fs.ErrNotExist) {
return sz, nil
}
if err != nil {
return sz, err
}
return optional.Some(st.Size()), nil
}
// Save stores a package blob
+2 -1
View File
@@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"net/http"
"net/url"
"os"
@@ -108,7 +109,7 @@ func convertAzureBlobErr(err error) error {
}
if bloberror.HasCode(err, bloberror.BlobNotFound) {
return os.ErrNotExist
return fs.ErrNotExist
}
var respErr *azcore.ResponseError
if !errors.As(err, &respErr) {
+2 -1
View File
@@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"net/url"
"os"
"path/filepath"
@@ -138,7 +139,7 @@ func (l *LocalStorage) ServeDirectURL(path, name, _ string, reqParams *ServeDire
}
func (l *LocalStorage) normalizeWalkError(err error) error {
if errors.Is(err, os.ErrNotExist) {
if errors.Is(err, fs.ErrNotExist) {
// ignore it because the file may be deleted during the walk, and we don't care about it
return nil
}
+2 -1
View File
@@ -4,6 +4,7 @@
package storage
import (
"io/fs"
"os"
"strings"
"testing"
@@ -72,7 +73,7 @@ func TestLocalStorageDelete(t *testing.T) {
if exists {
require.NoError(t, err)
} else {
require.ErrorIs(t, err, os.ErrNotExist)
require.ErrorIs(t, err, fs.ErrNotExist)
}
}
+3 -2
View File
@@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"net/http"
"net/url"
"os"
@@ -87,9 +88,9 @@ func convertMinioErr(err error, optMsg ...string) error {
// Convert two responses to standard analogues
switch errResp.Code {
case "NoSuchKey":
return wrapErr(os.ErrNotExist)
return wrapErr(fs.ErrNotExist)
case "AccessDenied":
return wrapErr(os.ErrPermission)
return wrapErr(fs.ErrPermission)
}
return wrapErr(err)