The outputfile is the absolute path + create intermediate dirs

master
Víctor Zamanillo 2020-08-17 17:49:14 +02:00
parent 6650e3665a
commit 6f3cb22b6a
2 changed files with 9 additions and 10 deletions

View File

@ -153,7 +153,7 @@ func (r *Runner) EnumerateSingleDomain(ctx context.Context, domain, output strin
}
if output != "" {
file, err := outputter.createFile(output, r.options.OutputDirectory, appendToFile)
file, err := outputter.createFile(output, appendToFile)
if err != nil {
gologger.Errorf("Could not create file %s for %s: %s\n", output, domain, err)
return err

View File

@ -5,7 +5,7 @@ import (
"errors"
"io"
"os"
"path"
"path/filepath"
"strings"
jsoniter "github.com/json-iterator/go"
@ -28,29 +28,28 @@ func NewOutputter(json bool) *OutPutter {
return &OutPutter{JSON: json}
}
func (o *OutPutter) createFile(filename, outputDirectory string, appendtoFile bool) (*os.File, error) {
func (o *OutPutter) createFile(filename string, appendtoFile bool) (*os.File, error) {
if filename == "" {
return nil, errors.New("empty filename")
}
absFilePath := filename
dir := filepath.Dir(filename)
if outputDirectory != "" {
if _, err := os.Stat(outputDirectory); os.IsNotExist(err) {
err := os.MkdirAll(outputDirectory, os.ModePerm)
if dir != "" {
if _, err := os.Stat(dir); os.IsNotExist(err) {
err := os.MkdirAll(dir, os.ModePerm)
if err != nil {
return nil, err
}
}
absFilePath = path.Join(outputDirectory, filename)
}
var file *os.File
var err error
if appendtoFile {
file, err = os.OpenFile(absFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
file, err = os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
} else {
file, err = os.Create(absFilePath)
file, err = os.Create(filename)
}
if err != nil {
return nil, err