diff --git a/coverage-badge.svg b/coverage-badge.svg index e032f81..bbe385b 100644 --- a/coverage-badge.svg +++ b/coverage-badge.svg @@ -2,5 +2,5 @@ coverage - 58.4% + 59.3% diff --git a/internal/services/reposervice/service.go b/internal/services/reposervice/service.go index ee5835b..fd0214f 100644 --- a/internal/services/reposervice/service.go +++ b/internal/services/reposervice/service.go @@ -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 { diff --git a/internal/services/reposervice/utils.go b/internal/services/reposervice/utils.go index e531f17..767aa5d 100644 --- a/internal/services/reposervice/utils.go +++ b/internal/services/reposervice/utils.go @@ -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 diff --git a/tests/integration/reposervice_forceupdate_test.go b/tests/integration/reposervice_forceupdate_test.go index 1eebbdd..5d0ea15 100644 --- a/tests/integration/reposervice_forceupdate_test.go +++ b/tests/integration/reposervice_forceupdate_test.go @@ -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)) })