Compare commits

..

2 commits

Author SHA1 Message Date
939f14eb86 fix: reduce memory usage
Some checks failed
Format and Lint / format-check (push) Failing after 4s
Format and Lint / test (push) Successful in 53s
2025-01-08 15:30:48 +03:00
0d56779189 feat: add altlinux prefix for repo 2025-01-07 18:32:20 +03:00
6 changed files with 27 additions and 12 deletions

View file

@ -2,5 +2,5 @@
<rect width="1100" height="20" fill="#555"/>
<rect x="60" width="50" height="20" fill="#4c1"/>
<text x="5" y="14" fill="#fff" font-family="Verdana" font-size="11">coverage</text>
<text x="70" y="14" fill="#fff" font-family="Verdana" font-size="11">58.4%</text>
<text x="70" y="14" fill="#fff" font-family="Verdana" font-size="11">59.3%</text>
</svg>

Before

Width:  |  Height:  |  Size: 341 B

After

Width:  |  Height:  |  Size: 341 B

View file

@ -46,7 +46,7 @@ func (c *TaskController) Upload(w http.ResponseWriter, r *http.Request) {
return
}
err := r.ParseMultipartForm(10240 << 20)
err := r.ParseMultipartForm(10 << 20)
if err != nil {
render.Render(w, r, &commonErrors.ErrResponse{
HTTPStatusCode: http.StatusBadRequest,
@ -57,7 +57,7 @@ func (c *TaskController) Upload(w http.ResponseWriter, r *http.Request) {
files := r.MultipartForm.File["files"]
for _, fileHeader := range files {
if fileHeader.Size > (1024 << 20) {
if fileHeader.Size > (4096 << 20) {
render.Render(w, r, &commonErrors.ErrResponse{
HTTPStatusCode: http.StatusBadRequest,
StatusText: "File too large",

View file

@ -74,6 +74,7 @@ func (s *Service) cleanUpAfterUpdate() {
func (s *Service) Update(force bool) error {
const REPO_NAME = "aides"
const DISTRO_ID = "altlinux"
architectures := []string{
"x86_64",
@ -141,6 +142,7 @@ func (s *Service) Update(force bool) error {
futureRepoPath := path.Join(
s.futureRepoPathPrefix(),
DISTRO_ID,
altRepo.Name,
)
@ -170,7 +172,7 @@ func (s *Service) Update(force bool) error {
"RPMS.aides",
fileInfo.Filename,
)
targetPath := path.Join("../../../../tasks/", localFilePath)
targetPath := path.Join("../../../../../tasks/", localFilePath)
err := createSymlink(targetPath, symLink)
if err != nil {
return err
@ -196,11 +198,13 @@ func (s *Service) Update(force bool) error {
currentRepoPath := path.Join(
s.currentRepoPathPrefix(),
DISTRO_ID,
altRepo.Name,
)
oldRepoPath := path.Join(
s.oldRepoPathPrefix(),
DISTRO_ID,
altRepo.Name,
)
@ -211,7 +215,7 @@ func (s *Service) Update(force bool) error {
return err
}
if err := os.Rename(
if err := renameIfExists(
futureRepoPath,
currentRepoPath,
); err != nil {

View file

@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"path"
"path/filepath"
"code.aides.space/aides-infra/aides-repo-api/internal/logger"
)
@ -82,7 +83,17 @@ func createSymlink(target, link string) error {
}
func renameIfExists(oldPath, newPath string) error {
log := logger.GetLogger()
log.Debug(filepath.Dir(newPath))
if _, err := os.Stat(oldPath); err == nil {
log.Debug(filepath.Dir(newPath))
if err = os.MkdirAll(
filepath.Dir(newPath),
os.ModePerm,
); err != nil {
return err
}
return os.Rename(oldPath, newPath)
} else if !os.IsNotExist(err) {
return err

View file

@ -86,7 +86,6 @@ func (s *Service) Upload(input *TaskUploadInput) error {
if err != nil {
return fmt.Errorf("can't open fileHeader %w", err)
}
defer file.Close()
if !strings.HasSuffix(fileHeader.Filename, ".rpm") {
return fmt.Errorf("invalid file type: only .rpm files are allowed")
@ -107,12 +106,13 @@ func (s *Service) Upload(input *TaskUploadInput) error {
if err != nil {
return err
}
defer outFile.Close()
_, err = io.Copy(outFile, file)
if err != nil {
return err
}
outFile.Close()
file.Close()
pkg, err := rpm.Open(filePath)
if err != nil {

View file

@ -88,7 +88,7 @@ func TestRepoService_ForceUpdate(t *testing.T) {
// CHECK
assert.NoError(t, err)
// TODO: check db
repoBasePath := path.Join(config.GetUploadDir(), "repo", "Sisyphus")
repoBasePath := path.Join(config.GetUploadDir(), "repo", "altlinux", "Sisyphus")
x86_64BasePath := path.Join(repoBasePath, "x86_64", "base")
x86_64RPMSPath := path.Join(repoBasePath, "x86_64", "RPMS.aides")
noarchBasePath := path.Join(repoBasePath, "noarch", "base")
@ -115,7 +115,7 @@ func TestRepoService_ForceUpdate(t *testing.T) {
rpmPath := path.Join(x86_64RPMSPath, fileName)
linkDest, err := os.Readlink(rpmPath)
assert.NoError(t, err)
assert.Equal(t, path.Join("../../../../tasks/1", fileName), linkDest)
assert.Equal(t, path.Join("../../../../../tasks/1", fileName), linkDest)
})
t.Run("Correct update (update)", func(t *testing.T) {
@ -181,7 +181,7 @@ func TestRepoService_ForceUpdate(t *testing.T) {
// CHECK
assert.NoError(t, err)
// TODO: check db
repoBasePath := path.Join(config.GetUploadDir(), "repo", "Sisyphus")
repoBasePath := path.Join(config.GetUploadDir(), "repo", "altlinux", "Sisyphus")
x86_64BasePath := path.Join(repoBasePath, "x86_64", "base")
x86_64RPMSPath := path.Join(repoBasePath, "x86_64", "RPMS.aides")
noarchBasePath := path.Join(repoBasePath, "noarch", "base")
@ -208,7 +208,7 @@ func TestRepoService_ForceUpdate(t *testing.T) {
rpmPath := path.Join(x86_64RPMSPath, fileName)
linkDest, err := os.Readlink(rpmPath)
assert.NoError(t, err)
assert.Equal(t, path.Join("../../../../tasks/1", fileName), linkDest)
assert.Equal(t, path.Join("../../../../../tasks/1", fileName), linkDest)
})
t.Run("Do not do anything if no updates", func(t *testing.T) {
@ -275,7 +275,7 @@ func TestRepoService_ForceUpdate(t *testing.T) {
// СHECK
assert.NoError(t, err)
repoBasePath := path.Join(config.GetUploadDir(), "repo", "Sisyphus")
repoBasePath := path.Join(config.GetUploadDir(), "repo", "altlinux", "Sisyphus")
_, err = os.Stat(repoBasePath)
assert.True(t, os.IsNotExist(err))
})