mirror of
https://github.com/containers/podman.git
synced 2025-12-05 21:32:22 +08:00
vendor of containers/(common, storage, image)
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
3
vendor/github.com/containers/common/pkg/util/util.go
generated
vendored
3
vendor/github.com/containers/common/pkg/util/util.go
generated
vendored
@@ -2,6 +2,7 @@ package util
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -19,6 +20,8 @@ const (
|
||||
UnknownPackage = "Unknown"
|
||||
)
|
||||
|
||||
var ErrInterrupt = errors.New("interrupted")
|
||||
|
||||
// Note: This function is copied from containers/podman libpod/util.go
|
||||
// Please see https://github.com/containers/common/pull/1460
|
||||
func queryPackageVersion(cmdArg ...string) string {
|
||||
|
||||
44
vendor/github.com/containers/common/pkg/util/util_supported.go
generated
vendored
44
vendor/github.com/containers/common/pkg/util/util_supported.go
generated
vendored
@@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"syscall"
|
||||
@@ -14,6 +15,7 @@ import (
|
||||
"github.com/containers/storage/pkg/homedir"
|
||||
"github.com/containers/storage/pkg/unshare"
|
||||
"github.com/sirupsen/logrus"
|
||||
terminal "golang.org/x/term"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -89,3 +91,45 @@ func GetRuntimeDir() (string, error) {
|
||||
}
|
||||
return rootlessRuntimeDir, nil
|
||||
}
|
||||
|
||||
// ReadPassword reads a password from the terminal without echo.
|
||||
func ReadPassword(fd int) ([]byte, error) {
|
||||
// Store and restore the terminal status on interruptions to
|
||||
// avoid that the terminal remains in the password state
|
||||
// This is necessary as for https://github.com/golang/go/issues/31180
|
||||
|
||||
oldState, err := terminal.GetState(fd)
|
||||
if err != nil {
|
||||
return make([]byte, 0), err
|
||||
}
|
||||
|
||||
type Buffer struct {
|
||||
Buffer []byte
|
||||
Error error
|
||||
}
|
||||
errorChannel := make(chan Buffer, 1)
|
||||
|
||||
// SIGINT and SIGTERM restore the terminal, otherwise the no-echo mode would remain intact
|
||||
interruptChannel := make(chan os.Signal, 1)
|
||||
signal.Notify(interruptChannel, syscall.SIGINT, syscall.SIGTERM)
|
||||
defer func() {
|
||||
signal.Stop(interruptChannel)
|
||||
close(interruptChannel)
|
||||
}()
|
||||
go func() {
|
||||
for range interruptChannel {
|
||||
if oldState != nil {
|
||||
_ = terminal.Restore(fd, oldState)
|
||||
}
|
||||
errorChannel <- Buffer{Buffer: make([]byte, 0), Error: ErrInterrupt}
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
buf, err := terminal.ReadPassword(fd)
|
||||
errorChannel <- Buffer{Buffer: buf, Error: err}
|
||||
}()
|
||||
|
||||
buf := <-errorChannel
|
||||
return buf.Buffer, buf.Error
|
||||
}
|
||||
|
||||
15
vendor/github.com/containers/common/pkg/util/util_windows.go
generated
vendored
15
vendor/github.com/containers/common/pkg/util/util_windows.go
generated
vendored
@@ -5,9 +5,24 @@ package util
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
terminal "golang.org/x/term"
|
||||
)
|
||||
|
||||
// getRuntimeDir returns the runtime directory
|
||||
func GetRuntimeDir() (string, error) {
|
||||
return "", errors.New("this function is not implemented for windows")
|
||||
}
|
||||
|
||||
// ReadPassword reads a password from the terminal.
|
||||
func ReadPassword(fd int) ([]byte, error) {
|
||||
oldState, err := terminal.GetState(fd)
|
||||
if err != nil {
|
||||
return make([]byte, 0), err
|
||||
}
|
||||
buf, err := terminal.ReadPassword(fd)
|
||||
if oldState != nil {
|
||||
_ = terminal.Restore(fd, oldState)
|
||||
}
|
||||
return buf, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user