working commit

This commit is contained in:
2026-02-04 18:17:36 +02:00
parent 219a4cb890
commit 55e8abcdd3
6 changed files with 287 additions and 25 deletions
+45 -4
View File
@@ -139,17 +139,36 @@ func (store *Storage) DeleteFile(collection, filename string) error {
}
const (
upsubdir = "uploads"
upsubdir = "uploads"
blobsubdir = "blobs"
)
func (store *Storage) makeUppath(upname string) string {
return filepath.Join(store.basepath, upsubdir, upname)
return filepath.Join(store.basepath, upsubdir, upname) + ".bin"
}
func (store *Storage) makeUpsubdir() string {
return filepath.Join(store.basepath, upsubdir)
}
func (store *Storage) makeBlobpath(upname string) string {
return filepath.Join(store.basepath, blobsubdir, upname) + ".bin"
}
func (store *Storage) makeBlobsubdir() string {
return filepath.Join(store.basepath, blobsubdir)
}
func (store *Storage) WriteUpload(digest string, source io.Reader) (int64, error) {
var err error
var recsize int64
uploadDir := store.makeUpsubdir()
err = os.MkdirAll(uploadDir, 0750)
if err != nil {
return recsize, err
}
uploadPath := store.makeUppath(digest)
uploadFile, err := os.OpenFile(uploadPath, os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
@@ -166,9 +185,31 @@ func (store *Storage) WriteUpload(digest string, source io.Reader) (int64, error
return recsize, err
}
func (st *Storage) RemoveUpload(digest string) error {
func (store *Storage) LinkUpload(reference, digest string) error {
var err error
uploadPath := st.makeUppath(digest)
uploadPath := store.makeUppath(reference)
blobPath := store.makeBlobpath(digest)
blobdir := store.makeBlobsubdir()
err = os.MkdirAll(blobdir, 0750)
if err != nil {
return err
}
err = os.Link(uploadPath, blobPath)
if err != nil {
return err
}
err = os.Remove(uploadPath)
if err != nil {
return err
}
return err
}
func (store *Storage) RemoveUpload(digest string) error {
var err error
uploadPath := store.makeUppath(digest)
err = os.Remove(uploadPath)
if err != nil {
return err