-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathfilesystem.go
More file actions
96 lines (77 loc) · 2.29 KB
/
filesystem.go
File metadata and controls
96 lines (77 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1
package docker
import (
"errors"
"os"
"strings"
"time"
"github.com/docker/docker/client"
"github.com/spf13/afero"
"go.mondoo.com/cnquery/v12/providers/os/connection/ssh/cat"
)
type FS struct {
Container string
dockerClient *client.Client
Connection *ContainerConnection
catFS *cat.Fs
}
func (fs *FS) Name() string {
return "dockerfs"
}
func (fs *FS) Create(name string) (afero.File, error) {
return nil, errors.New("create not implemented")
}
func (fs *FS) Mkdir(name string, perm os.FileMode) error {
return errors.New("mkdir not implemented")
}
func (fs *FS) MkdirAll(path string, perm os.FileMode) error {
return errors.New("mkdirall not implemented")
}
func isDockerClientSupported(path string) bool {
// This is incomplete. There are other things that are
// unsupported like tmpfs and paths the user mounted
// in the container.
// See https://docs.docker.com/engine/reference/commandline/cp/#corner-cases
unsupported := []string{"/proc", "/dev", "/sys"}
for _, v := range unsupported {
if v == path || strings.HasPrefix(path, v) {
return false
}
}
return true
}
func (fs *FS) Open(name string) (afero.File, error) {
if isDockerClientSupported(name) {
return FileOpen(fs.dockerClient, name, fs.Container, fs.Connection, fs.catFS)
} else {
return fs.catFS.Open(name)
}
}
func (fs *FS) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error) {
return nil, errors.New("openfile not implemented")
}
func (fs *FS) Remove(name string) error {
return errors.New("remove not implemented")
}
func (fs *FS) RemoveAll(path string) error {
return errors.New("removeall not implemented")
}
func (fs *FS) Rename(oldname, newname string) error {
return errors.New("rename not implemented")
}
func (fs *FS) Stat(name string) (os.FileInfo, error) {
return fs.catFS.Stat(name)
}
func (fs *FS) Chmod(name string, mode os.FileMode) error {
return errors.New("chmod not implemented")
}
func (fs *FS) Chtimes(name string, atime time.Time, mtime time.Time) error {
return errors.New("chtimes not implemented")
}
func (fs *FS) Chown(name string, uid, gid int) error {
return errors.New("chown not implemented")
}
func (fs *FS) ReadDir(name string) ([]os.FileInfo, error) {
return fs.catFS.ReadDir(name)
}