diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/sentry/fs/gofer/handles.go | 45 |
1 files changed, 15 insertions, 30 deletions
diff --git a/pkg/sentry/fs/gofer/handles.go b/pkg/sentry/fs/gofer/handles.go index a660c9230..a3e52aad6 100644 --- a/pkg/sentry/fs/gofer/handles.go +++ b/pkg/sentry/fs/gofer/handles.go @@ -62,43 +62,28 @@ func newHandles(ctx context.Context, file contextFile, flags fs.FileFlags) (*han return nil, err } + var p9flags p9.OpenFlags switch { case flags.Read && flags.Write: - hostFile, _, _, err := newFile.open(ctx, p9.ReadWrite) - if err != nil { - newFile.close(ctx) - return nil, err - } - h := &handles{ - File: newFile, - Host: hostFile, - } - return h, nil + p9flags = p9.ReadWrite case flags.Read && !flags.Write: - hostFile, _, _, err := newFile.open(ctx, p9.ReadOnly) - if err != nil { - newFile.close(ctx) - return nil, err - } - h := &handles{ - File: newFile, - Host: hostFile, - } - return h, nil + p9flags = p9.ReadOnly case !flags.Read && flags.Write: - hostFile, _, _, err := newFile.open(ctx, p9.WriteOnly) - if err != nil { - newFile.close(ctx) - return nil, err - } - h := &handles{ - File: newFile, - Host: hostFile, - } - return h, nil + p9flags = p9.WriteOnly default: panic("impossible fs.FileFlags") } + + hostFile, _, _, err := newFile.open(ctx, p9flags) + if err != nil { + newFile.close(ctx) + return nil, err + } + h := &handles{ + File: newFile, + Host: hostFile, + } + return h, nil } type handleReadWriter struct { |