Skip to content

Commit

Permalink
graph: do not remove tempfile when opening in viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
neolynx committed Dec 4, 2024
1 parent 88ef8ef commit 3a7de07
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions cmd/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"path/filepath"
"runtime"
"strings"
"time"

"github.com/aptly-dev/aptly/deb"
"github.com/aptly-dev/aptly/utils"
Expand Down Expand Up @@ -79,34 +78,23 @@ func aptlyGraph(cmd *commander.Command, args []string) error {
return err
}

defer func() {
_ = os.Remove(tempfilename)
}()

if output != "" {
err = utils.CopyFile(tempfilename, output)
if err != nil {
return fmt.Errorf("unable to copy %s -> %s: %s", tempfilename, output, err)
}

fmt.Printf("Output saved to %s\n", output)
_ = os.Remove(tempfilename)

Check warning on line 88 in cmd/graph.go

View check run for this annotation

Codecov / codecov/patch

cmd/graph.go#L88

Added line #L88 was not covered by tests
} else {
command := getOpenCommand()
fmt.Printf("Rendered to %s file: %s, trying to open it with: %s %s...\n", format, tempfilename, command, tempfilename)
fmt.Printf("Displaying %s file: %s %s\n", format, command, tempfilename)

Check warning on line 91 in cmd/graph.go

View check run for this annotation

Codecov / codecov/patch

cmd/graph.go#L91

Added line #L91 was not covered by tests

args := strings.Split(command, " ")

viewer := exec.Command(args[0], append(args[1:], tempfilename)...)
viewer.Stderr = os.Stderr
if err = viewer.Start(); err == nil {
// Wait for a second so that the visualizer has a chance to
// open the input file. This needs to be done even if we're
// waiting for the visualizer as it can be just a wrapper that
// spawns a browser tab and returns right away.
defer func(t <-chan time.Time) {
<-t
}(time.After(time.Second))
}
err = viewer.Start()

Check warning on line 97 in cmd/graph.go

View check run for this annotation

Codecov / codecov/patch

cmd/graph.go#L97

Added line #L97 was not covered by tests
}

return err
Expand Down

0 comments on commit 3a7de07

Please sign in to comment.