aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/kr/fs/walk.go
diff options
context:
space:
mode:
authorCharlie Doern <cdoern@redhat.com>2022-07-15 15:42:14 -0400
committerCharlie Doern <cdoern@redhat.com>2022-08-09 14:00:58 -0400
commit280f5d8cb01d115618d5ef131c718496a3b4900e (patch)
tree17e506cde2a18252da41096dbcc634ef485eff5e /vendor/github.com/kr/fs/walk.go
parentc33dc90ace724f920c14e41769ce237f5c5d14ec (diff)
downloadpodman-280f5d8cb01d115618d5ef131c718496a3b4900e.tar.gz
podman-280f5d8cb01d115618d5ef131c718496a3b4900e.tar.bz2
podman-280f5d8cb01d115618d5ef131c718496a3b4900e.zip
podman ssh work, using new c/common interface
implement new ssh interface into podman this completely redesigns the entire functionality of podman image scp, podman system connection add, and podman --remote. All references to golang.org/x/crypto/ssh have been moved to common as have native ssh/scp execs and the new usage of the sftp package. this PR adds a global flag, --ssh to podman which has two valid inputs `golang` and `native` where golang is the default. Users should not notice any difference in their everyday workflows if they continue using the golang option. UNLESS they have been using an improperly verified ssh key, this will now fail. This is because podman was incorrectly using the ssh callback method to IGNORE the ssh known hosts file which is very insecure and golang tells you not yo use this in production. The native paths allows for immense flexibility, with a new containers.conf field `SSH_CONFIG` that specifies a specific ssh config file to be used in all operations. Else the users ~/.ssh/config file will be used. podman --remote currently only uses the golang path, given its deep interconnection with dialing multiple clients and urls. My goal after this PR is to go back and abstract the idea of podman --remote from golang's dialed clients, as it should not be so intrinsically connected. Overall, this is a v1 of a long process of offering native ssh, and one that covers some good ground with podman system connection add and podman image scp. Signed-off-by: Charlie Doern <cdoern@redhat.com>
Diffstat (limited to 'vendor/github.com/kr/fs/walk.go')
-rw-r--r--vendor/github.com/kr/fs/walk.go95
1 files changed, 95 insertions, 0 deletions
diff --git a/vendor/github.com/kr/fs/walk.go b/vendor/github.com/kr/fs/walk.go
new file mode 100644
index 000000000..6ffa1e0b2
--- /dev/null
+++ b/vendor/github.com/kr/fs/walk.go
@@ -0,0 +1,95 @@
+// Package fs provides filesystem-related functions.
+package fs
+
+import (
+ "os"
+)
+
+// Walker provides a convenient interface for iterating over the
+// descendants of a filesystem path.
+// Successive calls to the Step method will step through each
+// file or directory in the tree, including the root. The files
+// are walked in lexical order, which makes the output deterministic
+// but means that for very large directories Walker can be inefficient.
+// Walker does not follow symbolic links.
+type Walker struct {
+ fs FileSystem
+ cur item
+ stack []item
+ descend bool
+}
+
+type item struct {
+ path string
+ info os.FileInfo
+ err error
+}
+
+// Walk returns a new Walker rooted at root.
+func Walk(root string) *Walker {
+ return WalkFS(root, new(fs))
+}
+
+// WalkFS returns a new Walker rooted at root on the FileSystem fs.
+func WalkFS(root string, fs FileSystem) *Walker {
+ info, err := fs.Lstat(root)
+ return &Walker{
+ fs: fs,
+ stack: []item{{root, info, err}},
+ }
+}
+
+// Step advances the Walker to the next file or directory,
+// which will then be available through the Path, Stat,
+// and Err methods.
+// It returns false when the walk stops at the end of the tree.
+func (w *Walker) Step() bool {
+ if w.descend && w.cur.err == nil && w.cur.info.IsDir() {
+ list, err := w.fs.ReadDir(w.cur.path)
+ if err != nil {
+ w.cur.err = err
+ w.stack = append(w.stack, w.cur)
+ } else {
+ for i := len(list) - 1; i >= 0; i-- {
+ path := w.fs.Join(w.cur.path, list[i].Name())
+ w.stack = append(w.stack, item{path, list[i], nil})
+ }
+ }
+ }
+
+ if len(w.stack) == 0 {
+ return false
+ }
+ i := len(w.stack) - 1
+ w.cur = w.stack[i]
+ w.stack = w.stack[:i]
+ w.descend = true
+ return true
+}
+
+// Path returns the path to the most recent file or directory
+// visited by a call to Step. It contains the argument to Walk
+// as a prefix; that is, if Walk is called with "dir", which is
+// a directory containing the file "a", Path will return "dir/a".
+func (w *Walker) Path() string {
+ return w.cur.path
+}
+
+// Stat returns info for the most recent file or directory
+// visited by a call to Step.
+func (w *Walker) Stat() os.FileInfo {
+ return w.cur.info
+}
+
+// Err returns the error, if any, for the most recent attempt
+// by Step to visit a file or directory. If a directory has
+// an error, w will not descend into that directory.
+func (w *Walker) Err() error {
+ return w.cur.err
+}
+
+// SkipDir causes the currently visited directory to be skipped.
+// If w is not on a directory, SkipDir has no effect.
+func (w *Walker) SkipDir() {
+ w.descend = false
+}