mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Add aggregator; improve itest workflow
* Factor JSON evaluation and construction base URLs out of of checker. * Move json path matching to util. * Add csaf_aggregator (as additional command) * Improve itest workflow to checkout the branch where it is running on. resolve #105 resolve #72 Co-authored-by: tschmidtb51 <65305130+tschmidtb51@users.noreply.github.com> Co-authored-by: Bernhard Reiter <bernhard@intevation.de> Co-authored-by: Fadi Abbud <fadi.abbud@intevation.de>
This commit is contained in:
parent
9da0589236
commit
8a1ebe0b7a
30 changed files with 2789 additions and 88 deletions
86
cmd/csaf_aggregator/lazytransaction.go
Normal file
86
cmd/csaf_aggregator/lazytransaction.go
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
// This file is Free Software under the MIT License
|
||||
// without warranty, see README.md and LICENSES/MIT.txt for details.
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2022 German Federal Office for Information Security (BSI) <https://www.bsi.bund.de>
|
||||
// Software-Engineering: 2022 Intevation GmbH <https://intevation.de>
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/csaf-poc/csaf_distribution/util"
|
||||
)
|
||||
|
||||
type lazyTransaction struct {
|
||||
src string
|
||||
dstDir string
|
||||
dst string
|
||||
}
|
||||
|
||||
func newLazyTransaction(src, dstDir string) *lazyTransaction {
|
||||
return &lazyTransaction{
|
||||
src: src,
|
||||
dstDir: dstDir,
|
||||
}
|
||||
}
|
||||
|
||||
func (lt *lazyTransaction) Src() string {
|
||||
return lt.src
|
||||
}
|
||||
|
||||
func (lt *lazyTransaction) Dst() (string, error) {
|
||||
if lt.dst != "" {
|
||||
return lt.dst, nil
|
||||
}
|
||||
|
||||
srcBase := filepath.Base(lt.src)
|
||||
|
||||
folder := filepath.Join(lt.dstDir, srcBase)
|
||||
|
||||
dst, err := util.MakeUniqDir(folder)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Copy old content into new.
|
||||
if err := util.DeepCopy(lt.dst, lt.src); err != nil {
|
||||
os.RemoveAll(dst)
|
||||
return "", err
|
||||
}
|
||||
lt.dst = dst
|
||||
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
func (lt *lazyTransaction) rollback() error {
|
||||
if lt.dst == "" {
|
||||
return nil
|
||||
}
|
||||
err := os.RemoveAll(lt.dst)
|
||||
lt.dst = ""
|
||||
return err
|
||||
}
|
||||
|
||||
func (lt *lazyTransaction) commit() error {
|
||||
if lt.dst == "" {
|
||||
return nil
|
||||
}
|
||||
defer func() { lt.dst = "" }()
|
||||
|
||||
// Switch directories.
|
||||
symlink := filepath.Join(lt.dstDir, filepath.Base(lt.src))
|
||||
if err := os.Symlink(lt.dstDir, symlink); err != nil {
|
||||
os.RemoveAll(lt.dstDir)
|
||||
return err
|
||||
}
|
||||
if err := os.Rename(symlink, lt.src); err != nil {
|
||||
os.RemoveAll(lt.dstDir)
|
||||
return err
|
||||
}
|
||||
|
||||
return os.RemoveAll(lt.src)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue