Skip to content

Commit

Permalink
cmd/create: Require -y to pull an image when not connected to a terminal
Browse files Browse the repository at this point in the history
It doesn't make sense to show the image download prompt when the
standard input and output streams are redirected to something other than
a terminal device.

During such non-interactive use, there's no way for the user to see the
prompt and the size of the image and then make a decision based on them.
The decision has to be made differently and earlier.  The user will
either never download or always download or will use 'skopeo inspect'
to decide for themself.

Secondly, when the input and output are not connected to a terminal, the
terminal escape sequences and the terminal-specific ioctl(2) requests
used to show the prompt won't work anyway.

#1428
  • Loading branch information
HarryMichal authored and debarshiray committed Dec 20, 2023
1 parent ecae5d6 commit 925e75a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,16 @@ func pullImage(image, release, authFile string) (bool, error) {
}

if promptForDownload {
if !term.IsTerminal(os.Stdin) || !term.IsTerminal(os.Stdout) {
var builder strings.Builder
fmt.Fprintf(&builder, "image required to create toolbox container.\n")
fmt.Fprintf(&builder, "Use option '--assumeyes' to download the image.\n")
fmt.Fprintf(&builder, "Run '%s --help' for usage.", executableBase)

errMsg := builder.String()
return false, errors.New(errMsg)
}

shouldPullImage = showPromptForDownload(imageFull)
}

Expand Down

0 comments on commit 925e75a

Please sign in to comment.