mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
Added check for output directory for collect
This commit is contained in:
parent
4cc3f7f7ac
commit
77b6a9ba7b
1 changed files with 14 additions and 10 deletions
|
|
@ -129,19 +129,23 @@ func CollectInventory(scannedResults *[]ScannedAsset, params *CollectParams) err
|
||||||
|
|
||||||
// write JSON data to file if output path is set using hive partitioning strategy
|
// write JSON data to file if output path is set using hive partitioning strategy
|
||||||
if outputPath != "" {
|
if outputPath != "" {
|
||||||
err = os.MkdirAll(outputPath, 0o644)
|
// make directory if it does exists
|
||||||
if err != nil {
|
exists, err := util.PathExists(outputPath)
|
||||||
log.Error().Err(err).Msg("failed to make directory for output")
|
if err == nil && !exists {
|
||||||
} else {
|
err = os.MkdirAll(outputPath, 0o644)
|
||||||
// make the output directory to store files
|
|
||||||
outputPath, err := util.MakeOutputDirectory(outputPath, false)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("failed to make output directory")
|
log.Error().Err(err).Msg("failed to make directory for output")
|
||||||
} else {
|
} else {
|
||||||
// write the output to the final path
|
// make the output directory to store files
|
||||||
err = os.WriteFile(path.Clean(fmt.Sprintf("%s/%s/%d.json", params.Host, outputPath, time.Now().Unix())), body, os.ModePerm)
|
outputPath, err := util.MakeOutputDirectory(outputPath, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msgf("failed to write data to file")
|
log.Error().Err(err).Msg("failed to make output directory")
|
||||||
|
} else {
|
||||||
|
// write the output to the final path
|
||||||
|
err = os.WriteFile(path.Clean(fmt.Sprintf("%s/%s/%d.json", params.Host, outputPath, time.Now().Unix())), body, os.ModePerm)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msgf("failed to write data to file")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue