aboutsummaryrefslogtreecommitdiffstats
path: root/modules/packages
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-11-15 08:08:59 +0000
committerGitHub <noreply@github.com>2022-11-15 16:08:59 +0800
commitc772934ff623b3a76efbe306f597695330a71287 (patch)
tree4639644b2bcc0e8ee3573283c8c7190a80b24a59 /modules/packages
parentde6dfb714153c17a06406c866805a17a476c63bd (diff)
downloadgitea-c772934ff623b3a76efbe306f597695330a71287.tar.gz
gitea-c772934ff623b3a76efbe306f597695330a71287.zip
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>
Diffstat (limited to 'modules/packages')
-rw-r--r--modules/packages/content_store.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/modules/packages/content_store.go b/modules/packages/content_store.go
index a3a5d1a666..be416ac269 100644
--- a/modules/packages/content_store.go
+++ b/modules/packages/content_store.go
@@ -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
+}