Add sandbox /etc/hosts when using host network
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
19
pkg/os/os.go
19
pkg/os/os.go
@@ -32,6 +32,7 @@ type OS interface {
|
||||
RemoveAll(path string) error
|
||||
OpenFifo(ctx context.Context, fn string, flag int, perm os.FileMode) (io.ReadWriteCloser, error)
|
||||
Stat(name string) (os.FileInfo, error)
|
||||
CopyFile(src, dest string, perm os.FileMode) error
|
||||
}
|
||||
|
||||
// RealOS is used to dispatch the real system level operations.
|
||||
@@ -56,3 +57,21 @@ func (RealOS) OpenFifo(ctx context.Context, fn string, flag int, perm os.FileMod
|
||||
func (RealOS) Stat(name string) (os.FileInfo, error) {
|
||||
return os.Stat(name)
|
||||
}
|
||||
|
||||
// CopyFile copys src file to dest file
|
||||
func (RealOS) CopyFile(src, dest string, perm os.FileMode) error {
|
||||
in, err := os.Open(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
|
||||
out, err := os.OpenFile(dest, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
_, err = io.Copy(out, in)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -34,7 +34,8 @@ type FakeOS struct {
|
||||
MkdirAllFn func(string, os.FileMode) error
|
||||
RemoveAllFn func(string) error
|
||||
OpenFifoFn func(context.Context, string, int, os.FileMode) (io.ReadWriteCloser, error)
|
||||
StatFn func(name string) (os.FileInfo, error)
|
||||
StatFn func(string) (os.FileInfo, error)
|
||||
CopyFileFn func(string, string, os.FileMode) error
|
||||
errors map[string]error
|
||||
}
|
||||
|
||||
@@ -118,7 +119,7 @@ func (f *FakeOS) OpenFifo(ctx context.Context, fn string, flag int, perm os.File
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Stat is a fake call that invokes Stat or just return nil.
|
||||
// Stat is a fake call that invokes StatFn or just return nil.
|
||||
func (f *FakeOS) Stat(name string) (os.FileInfo, error) {
|
||||
if err := f.getError("Stat"); err != nil {
|
||||
return nil, err
|
||||
@@ -129,3 +130,15 @@ func (f *FakeOS) Stat(name string) (os.FileInfo, error) {
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// CopyFile is a fake call that invokes CopyFileFn or just return nil.
|
||||
func (f *FakeOS) CopyFile(src, dest string, perm os.FileMode) error {
|
||||
if err := f.getError("CopyFile"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if f.CopyFileFn != nil {
|
||||
return f.CopyFileFn(src, dest, perm)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user