git: add archive integrity check
This commit is contained in:
parent
8b98573493
commit
9540efe9de
|
@ -341,8 +341,8 @@ func (r *GitRepositoryReconciler) sync(ctx context.Context, repository sourcev1.
|
|||
}
|
||||
defer unlock()
|
||||
|
||||
// archive artifact
|
||||
err = r.Storage.Archive(artifact, tmpGit, "")
|
||||
// archive artifact and check integrity
|
||||
err = r.Storage.Archive(artifact, tmpGit, "", true)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("storage archive error: %w", err)
|
||||
return sourcev1.GitRepositoryNotReady(repository, sourcev1.StorageOperationFailedReason, err.Error()), err
|
||||
|
|
|
@ -113,7 +113,7 @@ func (s *Storage) ArtifactExist(artifact sourcev1.Artifact) bool {
|
|||
}
|
||||
|
||||
// Archive creates a tar.gz to the artifact path from the given dir excluding the provided file extensions
|
||||
func (s *Storage) Archive(artifact sourcev1.Artifact, dir string, excludes string) error {
|
||||
func (s *Storage) Archive(artifact sourcev1.Artifact, dir string, excludes string, integrityCheck bool) error {
|
||||
if excludes == "" {
|
||||
excludes = "jpg,jpeg,gif,png,wmv,flv,tar.gz,zip"
|
||||
}
|
||||
|
@ -129,6 +129,23 @@ func (s *Storage) Archive(artifact sourcev1.Artifact, dir string, excludes strin
|
|||
if err != nil {
|
||||
return fmt.Errorf("command '%s' failed: %w", cmd, err)
|
||||
}
|
||||
|
||||
if integrityCheck {
|
||||
cmd = fmt.Sprintf("gunzip -t %s", artifact.Path)
|
||||
command = exec.CommandContext(ctx, "/bin/sh", "-c", cmd)
|
||||
err = command.Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("gzip integrity check failed")
|
||||
}
|
||||
|
||||
cmd = fmt.Sprintf("tar -tzf %s >/dev/null", artifact.Path)
|
||||
command = exec.CommandContext(ctx, "/bin/sh", "-c", cmd)
|
||||
err = command.Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("tar integrity check failed")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue