mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-02-23 03:45:47 -05:00
Co-authored-by: Aleksandr Gamzin alexgamz1119@gmail.com Adds support for the Apt-Rpm registry of the Alt Lunux distribution. Alt Linux uses RPM packages to store and distribute software to its users. But the logic of the Alt Linux package registry is different from the Red Hat package registry. I have added support for the Alt Linux package registry. ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [ ] in their respective `*_test.go` for unit tests. - [x] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [x] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [ ] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] I do not want this change to show in the release notes. - [x] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. Co-authored-by: Aleksandr Gamzin <gamzin@altlinux.org> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6351 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Alex619829 <alex619829@noreply.codeberg.org> Co-committed-by: Alex619829 <alex619829@noreply.codeberg.org>
81 lines
2 KiB
Go
81 lines
2 KiB
Go
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package packages
|
|
|
|
import (
|
|
"io"
|
|
|
|
"code.gitea.io/gitea/modules/util/filebuffer"
|
|
)
|
|
|
|
// HashedSizeReader provide methods to read, sum hashes and a Size method
|
|
type HashedSizeReader interface {
|
|
io.Reader
|
|
HashSummer
|
|
Size() int64
|
|
}
|
|
|
|
// HashedBuffer is buffer which calculates multiple checksums
|
|
type HashedBuffer struct {
|
|
*filebuffer.FileBackedBuffer
|
|
|
|
hash *MultiHasher
|
|
|
|
combinedWriter io.Writer
|
|
}
|
|
|
|
const DefaultMemorySize = 32 * 1024 * 1024
|
|
|
|
// NewHashedBuffer creates a hashed buffer with the default memory size
|
|
func NewHashedBuffer() (*HashedBuffer, error) {
|
|
return NewHashedBufferWithSize(DefaultMemorySize)
|
|
}
|
|
|
|
// NewHashedBufferWithSize creates a hashed buffer with a specific memory size
|
|
func NewHashedBufferWithSize(maxMemorySize int) (*HashedBuffer, error) {
|
|
b, err := filebuffer.New(maxMemorySize)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
hash := NewMultiHasher()
|
|
|
|
combinedWriter := io.MultiWriter(b, hash)
|
|
|
|
return &HashedBuffer{
|
|
b,
|
|
hash,
|
|
combinedWriter,
|
|
}, nil
|
|
}
|
|
|
|
// CreateHashedBufferFromReader creates a hashed buffer with the default memory size and copies the provided reader data into it.
|
|
func CreateHashedBufferFromReader(r io.Reader) (*HashedBuffer, error) {
|
|
return CreateHashedBufferFromReaderWithSize(r, DefaultMemorySize)
|
|
}
|
|
|
|
// CreateHashedBufferFromReaderWithSize creates a hashed buffer and copies the provided reader data into it.
|
|
func CreateHashedBufferFromReaderWithSize(r io.Reader, maxMemorySize int) (*HashedBuffer, error) {
|
|
b, err := NewHashedBufferWithSize(maxMemorySize)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
_, err = io.Copy(b, r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return b, nil
|
|
}
|
|
|
|
// Write implements io.Writer
|
|
func (b *HashedBuffer) Write(p []byte) (int, error) {
|
|
return b.combinedWriter.Write(p)
|
|
}
|
|
|
|
// Sums gets the MD5, SHA1, SHA256, SHA512 and BLAKE2B checksums of the data
|
|
func (b *HashedBuffer) Sums() (hashMD5, hashSHA1, hashSHA256, hashSHA512, hashBlake2b []byte) {
|
|
return b.hash.Sums()
|
|
}
|