feat: add altlinux prefix for repo

This commit is contained in:
Максим Слипенко 2025-01-07 18:32:20 +03:00
parent e4f9743dea
commit 0d56779189
4 changed files with 23 additions and 8 deletions

View file

@ -2,5 +2,5 @@
<rect width="1100" height="20" fill="#555"/> <rect width="1100" height="20" fill="#555"/>
<rect x="60" width="50" height="20" fill="#4c1"/> <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="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> </svg>

Before

Width:  |  Height:  |  Size: 341 B

After

Width:  |  Height:  |  Size: 341 B

View file

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

View file

@ -5,6 +5,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path" "path"
"path/filepath"
"code.aides.space/aides-infra/aides-repo-api/internal/logger" "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 { func renameIfExists(oldPath, newPath string) error {
log := logger.GetLogger()
log.Debug(filepath.Dir(newPath))
if _, err := os.Stat(oldPath); err == nil { 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) return os.Rename(oldPath, newPath)
} else if !os.IsNotExist(err) { } else if !os.IsNotExist(err) {
return err return err

View file

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