Skip to content

Commit

Permalink
local-capture: Ignore ErrNotExist when checking for outputDir
Browse files Browse the repository at this point in the history
Signed-off-by: Chance Zibolski <chance.zibolski@gmail.com>
  • Loading branch information
chancez committed Jul 19, 2024
1 parent 1d311c8 commit ce131d8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cmd/local_capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ func localCapture(ctx context.Context, log *slog.Logger, ifaces []string, netns
w = os.Stdout
} else {
fi, err := os.Stat(outputFile)
if err != nil {
if err != nil && !errors.Is(err, os.ErrNotExist) {
return err
}

fileName := outputFile
// if the output is a directory, generate a filename and store it in that directory
if fi.IsDir() {
if err == nil && fi.IsDir() {
outputDir := outputFile
hostname, _ := os.Hostname()
fileName = filepath.Join(outputDir, normalizeFilename(hostname, netns, handle.Interfaces(), conf.OutputFormat))
Expand Down Expand Up @@ -168,10 +168,10 @@ func localCaptureMultiNamespace(ctx context.Context, log *slog.Logger, ifaces []
return errors.New("--output-file is not specified, multi-namespace capture requires --output-file to point to a directory")
}
fi, err := os.Stat(outputDir)
if err != nil {
if err != nil && !errors.Is(err, os.ErrNotExist) {
return err
}
if !fi.IsDir() {
if err == nil && fi.IsDir() {
return fmt.Errorf("%s is not a directory, multi-namespace capture requires --output-file to point to a directory", outputDir)
}

Expand Down

0 comments on commit ce131d8

Please sign in to comment.