1
0
Fork 0
forked from forgejo/forgejo

Adjust gitea doctor --run storages to check all storage types (#21785)

The doctor check `storages` currently only checks the attachment
storage. This PR adds some basic garbage collection functionality for
the other types of storage.

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
zeripath 2022-11-15 08:08:59 +00:00 committed by GitHub
parent de6dfb7141
commit c772934ff6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 296 additions and 31 deletions

View file

@ -7,8 +7,10 @@ package packages
import (
"io"
"path"
"strings"
"code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/util"
)
// BlobHash256Key is the key to address a blob content
@ -45,3 +47,13 @@ func (s *ContentStore) Delete(key BlobHash256Key) error {
func KeyToRelativePath(key BlobHash256Key) string {
return path.Join(string(key)[0:2], string(key)[2:4], string(key))
}
// RelativePathToKey converts a relative path aa/bb/aabb000000... to the sha256 key aabb000000...
func RelativePathToKey(relativePath string) (BlobHash256Key, error) {
parts := strings.SplitN(relativePath, "/", 3)
if len(parts) != 3 || len(parts[0]) != 2 || len(parts[1]) != 2 || len(parts[2]) < 4 || parts[0]+parts[1] != parts[2][0:4] {
return "", util.ErrInvalidArgument
}
return BlobHash256Key(parts[2]), nil
}