Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Graph deleted before aptly exits #1214

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
} 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)

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()
}

return err
Expand Down
2 changes: 2 additions & 0 deletions system/t14_graph/CreateGraphOutputTest_gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Generating graph...
Output saved to /tmp/aptly-graph.png
2 changes: 2 additions & 0 deletions system/t14_graph/CreateGraphTest_gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Generating graph...
Displaying png file: xdg-open /tmp/aptly-graph1173098610.png
33 changes: 33 additions & 0 deletions system/t14_graph/graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
Test aptly graph
"""

import os
import re

from lib import BaseTest


class CreateGraphTest(BaseTest):
"""
open graph in viewer
"""
fixtureCmds = ["mkdir -p ../build", "ln -fs /bin/true ../build/xdg-open"]
environmentOverride = {"PATH": os.environ["PATH"] + ":../build"}
runCmd = "aptly graph"

def outputMatchPrepare(self, s):
return re.sub(r"[0-9]", "", s)

def teardown(self):
self.run_cmd(["rm", "-f", "../build/xdg-open"])


class CreateGraphOutputTest(BaseTest):
"""
open graph in viewer
"""
runCmd = "aptly graph -output /tmp/aptly-graph.png"

def teardown(self):
self.run_cmd(["rm", "-f", "/tmp/aptly-graph.png"])
Loading