Compare commits
No commits in common. "939f14eb86fd0aa78edf164b5e9eadc9f6d4a174" and "e4f9743dea35a369db2614609adec3d5b2c4e75e" have entirely different histories.
939f14eb86
...
e4f9743dea
6 changed files with 12 additions and 27 deletions
|
@ -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">59.3%</text>
|
<text x="70" y="14" fill="#fff" font-family="Verdana" font-size="11">58.4%</text>
|
||||||
</svg>
|
</svg>
|
||||||
|
|
Before Width: | Height: | Size: 341 B After Width: | Height: | Size: 341 B |
|
@ -46,7 +46,7 @@ func (c *TaskController) Upload(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := r.ParseMultipartForm(10 << 20)
|
err := r.ParseMultipartForm(10240 << 20)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
render.Render(w, r, &commonErrors.ErrResponse{
|
render.Render(w, r, &commonErrors.ErrResponse{
|
||||||
HTTPStatusCode: http.StatusBadRequest,
|
HTTPStatusCode: http.StatusBadRequest,
|
||||||
|
@ -57,7 +57,7 @@ func (c *TaskController) Upload(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
files := r.MultipartForm.File["files"]
|
files := r.MultipartForm.File["files"]
|
||||||
for _, fileHeader := range files {
|
for _, fileHeader := range files {
|
||||||
if fileHeader.Size > (4096 << 20) {
|
if fileHeader.Size > (1024 << 20) {
|
||||||
render.Render(w, r, &commonErrors.ErrResponse{
|
render.Render(w, r, &commonErrors.ErrResponse{
|
||||||
HTTPStatusCode: http.StatusBadRequest,
|
HTTPStatusCode: http.StatusBadRequest,
|
||||||
StatusText: "File too large",
|
StatusText: "File too large",
|
||||||
|
|
|
@ -74,7 +74,6 @@ 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",
|
||||||
|
@ -142,7 +141,6 @@ func (s *Service) Update(force bool) error {
|
||||||
|
|
||||||
futureRepoPath := path.Join(
|
futureRepoPath := path.Join(
|
||||||
s.futureRepoPathPrefix(),
|
s.futureRepoPathPrefix(),
|
||||||
DISTRO_ID,
|
|
||||||
altRepo.Name,
|
altRepo.Name,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -172,7 +170,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
|
||||||
|
@ -198,13 +196,11 @@ 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,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -215,7 +211,7 @@ func (s *Service) Update(force bool) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := renameIfExists(
|
if err := os.Rename(
|
||||||
futureRepoPath,
|
futureRepoPath,
|
||||||
currentRepoPath,
|
currentRepoPath,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
|
|
|
@ -5,7 +5,6 @@ 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"
|
||||||
)
|
)
|
||||||
|
@ -83,17 +82,7 @@ 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
|
||||||
|
|
|
@ -86,6 +86,7 @@ func (s *Service) Upload(input *TaskUploadInput) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't open fileHeader %w", err)
|
return fmt.Errorf("can't open fileHeader %w", err)
|
||||||
}
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
if !strings.HasSuffix(fileHeader.Filename, ".rpm") {
|
if !strings.HasSuffix(fileHeader.Filename, ".rpm") {
|
||||||
return fmt.Errorf("invalid file type: only .rpm files are allowed")
|
return fmt.Errorf("invalid file type: only .rpm files are allowed")
|
||||||
|
@ -106,13 +107,12 @@ func (s *Service) Upload(input *TaskUploadInput) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer outFile.Close()
|
||||||
|
|
||||||
_, err = io.Copy(outFile, file)
|
_, err = io.Copy(outFile, file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
outFile.Close()
|
|
||||||
file.Close()
|
|
||||||
|
|
||||||
pkg, err := rpm.Open(filePath)
|
pkg, err := rpm.Open(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -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", "altlinux", "Sisyphus")
|
repoBasePath := path.Join(config.GetUploadDir(), "repo", "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", "altlinux", "Sisyphus")
|
repoBasePath := path.Join(config.GetUploadDir(), "repo", "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", "altlinux", "Sisyphus")
|
repoBasePath := path.Join(config.GetUploadDir(), "repo", "Sisyphus")
|
||||||
_, err = os.Stat(repoBasePath)
|
_, err = os.Stat(repoBasePath)
|
||||||
assert.True(t, os.IsNotExist(err))
|
assert.True(t, os.IsNotExist(err))
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue