GoPLS Viewer

Home|gopls/godoc/vfs/emptyvfs.go
1// Copyright 2016 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package vfs
6
7import (
8    "fmt"
9    "os"
10    "time"
11)
12
13// NewNameSpace returns a NameSpace pre-initialized with an empty
14// emulated directory mounted on the root mount point "/". This
15// allows directory traversal routines to work properly even if
16// a folder is not explicitly mounted at root by the user.
17func NewNameSpace() NameSpace {
18    ns := NameSpace{}
19    ns.Bind("/", &emptyVFS{}, "/"BindReplace)
20    return ns
21}
22
23// type emptyVFS emulates a FileSystem consisting of an empty directory
24type emptyVFS struct{}
25
26// Open implements Opener. Since emptyVFS is an empty directory, all
27// attempts to open a file should returns errors.
28func (e *emptyVFSOpen(path string) (ReadSeekClosererror) {
29    if path == "/" {
30        return nilfmt.Errorf("open: / is a directory")
31    }
32    return nilos.ErrNotExist
33}
34
35// Stat returns os.FileInfo for an empty directory if the path is
36// is root "/" or error. os.FileInfo is implemented by emptyVFS
37func (e *emptyVFSStat(path string) (os.FileInfoerror) {
38    if path == "/" {
39        return enil
40    }
41    return nilos.ErrNotExist
42}
43
44func (e *emptyVFSLstat(path string) (os.FileInfoerror) {
45    return e.Stat(path)
46}
47
48// ReadDir returns an empty os.FileInfo slice for "/", else error.
49func (e *emptyVFSReadDir(path string) ([]os.FileInfoerror) {
50    if path == "/" {
51        return []os.FileInfo{}, nil
52    }
53    return nilos.ErrNotExist
54}
55
56func (e *emptyVFSString() string {
57    return "emptyVFS(/)"
58}
59
60func (e *emptyVFSRootType(path stringRootType {
61    return ""
62}
63
64// These functions below implement os.FileInfo for the single
65// empty emulated directory.
66
67func (e *emptyVFSName() string {
68    return "/"
69}
70
71func (e *emptyVFSSize() int64 {
72    return 0
73}
74
75func (e *emptyVFSMode() os.FileMode {
76    return os.ModeDir | os.ModePerm
77}
78
79func (e *emptyVFSModTime() time.Time {
80    return time.Time{}
81}
82
83func (e *emptyVFSIsDir() bool {
84    return true
85}
86
87func (e *emptyVFSSys() interface{} {
88    return nil
89}
90
MembersX
emptyVFS.Name.e
NewNameSpace
emptyVFS.ReadDir.e
emptyVFS.Name
emptyVFS.Stat.e
emptyVFS.Sys
emptyVFS.RootType.e
emptyVFS.Mode
emptyVFS.String.e
emptyVFS.Size
NewNameSpace.ns
emptyVFS
emptyVFS.Lstat.e
emptyVFS.ReadDir
emptyVFS.String
emptyVFS.Size.e
emptyVFS.Mode.e
emptyVFS.ModTime
fmt
emptyVFS.Open.path
emptyVFS.Sys.e
emptyVFS.Stat
emptyVFS.ReadDir.path
emptyVFS.RootType
emptyVFS.RootType.path
emptyVFS.ModTime.e
emptyVFS.IsDir.e
os
time
emptyVFS.IsDir
emptyVFS.Stat.path
emptyVFS.Lstat
emptyVFS.Lstat.path
emptyVFS.Open.e
emptyVFS.Open
Members
X