Skip to content

Commit fd4f7eb

Browse files
committed
remove prefixed io
The main process is now handling what output to print, so it doesn't do any good to try and run it through prefixedio, which is only adding extra coordination to echo the same data.
1 parent 1d9d829 commit fd4f7eb

3 files changed

Lines changed: 6 additions & 99 deletions

File tree

‎go.mod‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ require (
8484
github.com/lusis/go-artifactory v0.0.0-20160115162124-7e4ce345df82
8585
github.com/masterzen/simplexml v0.0.0-20190410153822-31eea3082786 // indirect
8686
github.com/masterzen/winrm v0.0.0-20200615185753-c42b5136ff88
87-
github.com/mattn/go-colorable v0.1.8
87+
github.com/mattn/go-colorable v0.1.8 // indirect
8888
github.com/mattn/go-isatty v0.0.12
8989
github.com/mattn/go-shellwords v1.0.4
9090
github.com/miekg/dns v1.0.8 // indirect
@@ -97,7 +97,6 @@ require (
9797
github.com/mitchellh/gox v1.0.1
9898
github.com/mitchellh/mapstructure v1.1.2
9999
github.com/mitchellh/panicwrap v1.0.0
100-
github.com/mitchellh/prefixedio v0.0.0-20190213213902-5733675afd51
101100
github.com/mitchellh/reflectwalk v1.0.1
102101
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
103102
github.com/packer-community/winrmcp v0.0.0-20180921211025-c76d91c1e7db

‎go.sum‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,6 @@ github.com/hashicorp/go-msgpack v0.5.4 h1:SFT72YqIkOcLdWJUYcriVX7hbrZpwc/f7h8aW2
246246
github.com/hashicorp/go-msgpack v0.5.4/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
247247
github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o=
248248
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
249-
github.com/hashicorp/go-plugin v1.3.0 h1:4d/wJojzvHV1I4i/rrjVaeuyxWrLzDE1mDCyDy8fXS8=
250-
github.com/hashicorp/go-plugin v1.3.0/go.mod h1:F9eH4LrE/ZsRdbwhfjs9k9HoDUwAHnYtXdgmf1AVNs0=
251249
github.com/hashicorp/go-retryablehttp v0.5.2 h1:AoISa4P4IsW0/m4T6St8Yw38gTl5GtBAgfkhYh1xAz4=
252250
github.com/hashicorp/go-retryablehttp v0.5.2/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
253251
github.com/hashicorp/go-rootcerts v1.0.0 h1:Rqb66Oo1X/eSV1x66xbDccZjhJigjg0+e82kpwzSwCI=
@@ -384,8 +382,6 @@ github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQz
384382
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
385383
github.com/mitchellh/panicwrap v1.0.0 h1:67zIyVakCIvcs69A0FGfZjBdPleaonSgGlXRSRlb6fE=
386384
github.com/mitchellh/panicwrap v1.0.0/go.mod h1:pKvZHwWrZowLUzftuFq7coarnxbBXU4aQh3N0BJOeeA=
387-
github.com/mitchellh/prefixedio v0.0.0-20190213213902-5733675afd51 h1:eD92Am0Qf3rqhsOeA1zwBHSfRkoHrt4o6uORamdmJP8=
388-
github.com/mitchellh/prefixedio v0.0.0-20190213213902-5733675afd51/go.mod h1:kB1naBgV9ORnkiTVeyJOI1DavaJkG4oNIq0Af6ZVKUo=
389385
github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY=
390386
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
391387
github.com/mitchellh/reflectwalk v1.0.1 h1:FVzMWA5RllMAKIdUSC8mdWo3XtwoecrH79BY70sEEpE=

‎main.go‎

Lines changed: 5 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ package main
33
import (
44
"encoding/json"
55
"fmt"
6-
"io"
76
"io/ioutil"
87
"log"
98
"net"
109
"os"
1110
"path/filepath"
1211
"runtime"
1312
"strings"
14-
"sync"
1513

1614
"github.com/hashicorp/go-plugin"
1715
"github.com/hashicorp/terraform-svchost/disco"
@@ -21,12 +19,10 @@ import (
2119
"github.com/hashicorp/terraform/httpclient"
2220
"github.com/hashicorp/terraform/internal/logging"
2321
"github.com/hashicorp/terraform/version"
24-
"github.com/mattn/go-colorable"
2522
"github.com/mattn/go-shellwords"
2623
"github.com/mitchellh/cli"
2724
"github.com/mitchellh/colorstring"
2825
"github.com/mitchellh/panicwrap"
29-
"github.com/mitchellh/prefixedio"
3026

3127
backendInit "github.com/hashicorp/terraform/backend/init"
3228
)
@@ -59,15 +55,8 @@ func realMain() int {
5955
defer os.Remove(logTempFile.Name())
6056
defer logTempFile.Close()
6157

62-
// Setup the prefixed readers that send data properly to
63-
// stdout/stderr.
64-
doneCh := make(chan struct{})
65-
outR, outW := io.Pipe()
66-
go copyOutput(outR, doneCh)
67-
6858
// Create the configuration for panicwrap and wrap our executable
6959
wrapConfig.Handler = logging.PanicHandler(logTempFile)
70-
wrapConfig.Stdout = outW
7160
wrapConfig.IgnoreSignals = ignoreSignals
7261
wrapConfig.ForwardSignals = forwardSignals
7362
exitStatus, err := panicwrap.Wrap(&wrapConfig)
@@ -76,36 +65,18 @@ func realMain() int {
7665
return 1
7766
}
7867

79-
// If >= 0, we're the parent, so just exit
80-
if exitStatus >= 0 {
81-
// Close the stdout writer so that our copy process can finish
82-
outW.Close()
83-
84-
// Wait for the output copying to finish
85-
<-doneCh
86-
87-
return exitStatus
88-
}
89-
90-
// We're the child, so just close the tempfile we made in order to
91-
// save file handles since the tempfile is only used by the parent.
92-
logTempFile.Close()
68+
return exitStatus
9369
}
9470

9571
// Call the real main
9672
return wrappedMain()
9773
}
9874

9975
func init() {
100-
Ui = &cli.PrefixedUi{
101-
AskPrefix: OutputPrefix,
102-
OutputPrefix: OutputPrefix,
103-
InfoPrefix: OutputPrefix,
104-
ErrorPrefix: ErrorPrefix,
105-
Ui: &cli.BasicUi{
106-
Writer: os.Stdout,
107-
Reader: os.Stdin,
108-
},
76+
Ui = &cli.BasicUi{
77+
Writer: os.Stdout,
78+
ErrorWriter: os.Stderr,
79+
Reader: os.Stdin,
10980
}
11081
}
11182

@@ -299,65 +270,6 @@ func wrappedMain() int {
299270
return exitCode
300271
}
301272

302-
// copyOutput uses output prefixes to determine whether data on stdout
303-
// should go to stdout or stderr. This is due to panicwrap using stderr
304-
// as the log and error channel.
305-
func copyOutput(r io.Reader, doneCh chan<- struct{}) {
306-
defer close(doneCh)
307-
308-
pr, err := prefixedio.NewReader(r)
309-
if err != nil {
310-
panic(err)
311-
}
312-
313-
stderrR, err := pr.Prefix(ErrorPrefix)
314-
if err != nil {
315-
panic(err)
316-
}
317-
stdoutR, err := pr.Prefix(OutputPrefix)
318-
if err != nil {
319-
panic(err)
320-
}
321-
defaultR, err := pr.Prefix("")
322-
if err != nil {
323-
panic(err)
324-
}
325-
326-
var stdout io.Writer = os.Stdout
327-
var stderr io.Writer = os.Stderr
328-
329-
if runtime.GOOS == "windows" {
330-
stdout = colorable.NewColorableStdout()
331-
stderr = colorable.NewColorableStderr()
332-
333-
// colorable is not concurrency-safe when stdout and stderr are the
334-
// same console, so we need to add some synchronization to ensure that
335-
// we can't be concurrently writing to both stderr and stdout at
336-
// once, or else we get intermingled writes that create gibberish
337-
// in the console.
338-
wrapped := synchronizedWriters(stdout, stderr)
339-
stdout = wrapped[0]
340-
stderr = wrapped[1]
341-
}
342-
343-
var wg sync.WaitGroup
344-
wg.Add(3)
345-
go func() {
346-
defer wg.Done()
347-
io.Copy(stderr, stderrR)
348-
}()
349-
go func() {
350-
defer wg.Done()
351-
io.Copy(stdout, stdoutR)
352-
}()
353-
go func() {
354-
defer wg.Done()
355-
io.Copy(stdout, defaultR)
356-
}()
357-
358-
wg.Wait()
359-
}
360-
361273
func mergeEnvArgs(envName string, cmd string, args []string) ([]string, error) {
362274
v := os.Getenv(envName)
363275
if v == "" {

0 commit comments

Comments
 (0)