Skip to content

Commit

Permalink
Windows collector default to current working directory rather than fa…
Browse files Browse the repository at this point in the history
…iling
  • Loading branch information
lkarlslund committed Jan 5, 2024
1 parent 7de1a25 commit d29473d
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

var (
wrapcollector = &cobra.Command{}
datapath = wrapcollector.Flags().String("outputpath", "", "Dump output JSON file in this folder")
datapath = wrapcollector.Flags().String("outputpath", ".", "Dump output JSON file in this folder")
loglevel = wrapcollector.Flags().String("loglevel", "info", "Console log level")
logfile = wrapcollector.Flags().String("logfile", "", "Log file")
logfilelevel = wrapcollector.Flags().String("logfilelevel", "info", "Log file log level")
Expand Down Expand Up @@ -49,21 +49,23 @@ func Execute(cmd *cobra.Command, args []string) error {

outputpath := *datapath

err = os.MkdirAll(outputpath, 0600)
if err != nil {
return fmt.Errorf("Problem accessing output folder: %v", err)
if outputpath == "" {
ui.Warn().Msg("Missing -outputpath parameter - writing file to current directory")
outputpath = "."
}

if _, err := os.Stat(outputpath); os.IsNotExist(err) && outputpath != "." {
err = os.MkdirAll(outputpath, 0600)
if err != nil {
return fmt.Errorf("Problem accessing output folder: %v", err)
}
}

info, err := collect.Collect()
if err != nil {
return err
}

if outputpath == "" {
ui.Warn().Msg("Missing -outputpath parameter - writing file to current directory")
outputpath = "."
}

targetname := info.Machine.Name + localmachine.Suffix
if info.Machine.IsDomainJoined {
targetname = info.Machine.Name + "$" + info.Machine.Domain + localmachine.Suffix
Expand Down

0 comments on commit d29473d

Please sign in to comment.