mirror of
https://github.com/rclone/rclone
synced 2025-01-04 05:06:24 +01:00
vfs: rename Lookup to Stat to be more in keeping with os
This commit is contained in:
parent
e8883e9fdb
commit
7e065440fb
@ -120,7 +120,7 @@ func (of *openFiles) Close(fh uint64) (errc int) {
|
|||||||
|
|
||||||
// lookup a Node given a path
|
// lookup a Node given a path
|
||||||
func (fsys *FS) lookupNode(path string) (node vfs.Node, errc int) {
|
func (fsys *FS) lookupNode(path string) (node vfs.Node, errc int) {
|
||||||
node, err := fsys.VFS.Lookup(path)
|
node, err := fsys.VFS.Stat(path)
|
||||||
return node, translateError(err)
|
return node, translateError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ var _ fusefs.NodeRequestLookuper = (*Dir)(nil)
|
|||||||
// Lookup need not to handle the names "." and "..".
|
// Lookup need not to handle the names "." and "..".
|
||||||
func (d *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.LookupResponse) (node fusefs.Node, err error) {
|
func (d *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.LookupResponse) (node fusefs.Node, err error) {
|
||||||
defer fs.Trace(d, "name=%q", req.Name)("node=%+v, err=%v", &node, &err)
|
defer fs.Trace(d, "name=%q", req.Name)("node=%+v, err=%v", &node, &err)
|
||||||
mnode, err := d.Dir.Lookup(req.Name)
|
mnode, err := d.Dir.Stat(req.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, translateError(err)
|
return nil, translateError(err)
|
||||||
}
|
}
|
||||||
|
26
vfs/dir.go
26
vfs/dir.go
@ -219,10 +219,10 @@ func (d *Dir) _readDir() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// lookup a single item in the directory
|
// stat a single item in the directory
|
||||||
//
|
//
|
||||||
// returns ENOENT if not found.
|
// returns ENOENT if not found.
|
||||||
func (d *Dir) lookup(leaf string) (Node, error) {
|
func (d *Dir) stat(leaf string) (Node, error) {
|
||||||
d.mu.Lock()
|
d.mu.Lock()
|
||||||
defer d.mu.Unlock()
|
defer d.mu.Unlock()
|
||||||
err := d._readDir()
|
err := d._readDir()
|
||||||
@ -269,23 +269,23 @@ func (d *Dir) SetModTime(modTime time.Time) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lookup looks up a specific entry in the receiver.
|
// Stat looks up a specific entry in the receiver.
|
||||||
//
|
//
|
||||||
// Lookup should return a Node corresponding to the entry. If the
|
// Stat should return a Node corresponding to the entry. If the
|
||||||
// name does not exist in the directory, Lookup should return ENOENT.
|
// name does not exist in the directory, Stat should return ENOENT.
|
||||||
//
|
//
|
||||||
// Lookup need not to handle the names "." and "..".
|
// Stat need not to handle the names "." and "..".
|
||||||
func (d *Dir) Lookup(name string) (node Node, err error) {
|
func (d *Dir) Stat(name string) (node Node, err error) {
|
||||||
path := path.Join(d.path, name)
|
path := path.Join(d.path, name)
|
||||||
// fs.Debugf(path, "Dir.Lookup")
|
// fs.Debugf(path, "Dir.Stat")
|
||||||
node, err = d.lookup(name)
|
node, err = d.stat(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != ENOENT {
|
if err != ENOENT {
|
||||||
fs.Errorf(path, "Dir.Lookup error: %v", err)
|
fs.Errorf(path, "Dir.Stat error: %v", err)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// fs.Debugf(path, "Dir.Lookup OK")
|
// fs.Debugf(path, "Dir.Stat OK")
|
||||||
return node, nil
|
return node, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,7 +408,7 @@ func (d *Dir) RemoveName(name string) error {
|
|||||||
}
|
}
|
||||||
path := path.Join(d.path, name)
|
path := path.Join(d.path, name)
|
||||||
// fs.Debugf(path, "Dir.Remove")
|
// fs.Debugf(path, "Dir.Remove")
|
||||||
node, err := d.lookup(name)
|
node, err := d.stat(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Errorf(path, "Dir.Remove error: %v", err)
|
fs.Errorf(path, "Dir.Remove error: %v", err)
|
||||||
return err
|
return err
|
||||||
@ -424,7 +424,7 @@ func (d *Dir) Rename(oldName, newName string, destDir *Dir) error {
|
|||||||
oldPath := path.Join(d.path, oldName)
|
oldPath := path.Join(d.path, oldName)
|
||||||
newPath := path.Join(destDir.path, newName)
|
newPath := path.Join(destDir.path, newName)
|
||||||
// fs.Debugf(oldPath, "Dir.Rename to %q", newPath)
|
// fs.Debugf(oldPath, "Dir.Rename to %q", newPath)
|
||||||
oldNode, err := d.lookup(oldName)
|
oldNode, err := d.stat(oldName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Errorf(oldPath, "Dir.Rename error: %v", err)
|
fs.Errorf(oldPath, "Dir.Rename error: %v", err)
|
||||||
return err
|
return err
|
||||||
|
27
vfs/vfs.go
27
vfs/vfs.go
@ -129,8 +129,11 @@ func NewInode() (inode uint64) {
|
|||||||
return atomic.AddUint64(&inodeCount, 1)
|
return atomic.AddUint64(&inodeCount, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lookup finds the Node by path starting from the root
|
// Stat finds the Node by path starting from the root
|
||||||
func (vfs *VFS) Lookup(path string) (node Node, err error) {
|
//
|
||||||
|
// It is the equivalent of os.Stat - Node contains the os.FileInfo
|
||||||
|
// interface.
|
||||||
|
func (vfs *VFS) Stat(path string) (node Node, err error) {
|
||||||
node = vfs.root
|
node = vfs.root
|
||||||
for path != "" {
|
for path != "" {
|
||||||
i := strings.IndexRune(path, '/')
|
i := strings.IndexRune(path, '/')
|
||||||
@ -148,28 +151,10 @@ func (vfs *VFS) Lookup(path string) (node Node, err error) {
|
|||||||
// We need to look in a directory, but found a file
|
// We need to look in a directory, but found a file
|
||||||
return nil, ENOENT
|
return nil, ENOENT
|
||||||
}
|
}
|
||||||
node, err = dir.Lookup(name)
|
node, err = dir.Stat(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Statfs is called to obtain file system metadata.
|
|
||||||
// It should write that data to resp.
|
|
||||||
func (vfs *VFS) Statfs() error {
|
|
||||||
/* FIXME
|
|
||||||
const blockSize = 4096
|
|
||||||
const fsBlocks = (1 << 50) / blockSize
|
|
||||||
resp.Blocks = fsBlocks // Total data blocks in file system.
|
|
||||||
resp.Bfree = fsBlocks // Free blocks in file system.
|
|
||||||
resp.Bavail = fsBlocks // Free blocks in file system if you're not root.
|
|
||||||
resp.Files = 1E9 // Total files in file system.
|
|
||||||
resp.Ffree = 1E9 // Free files in file system.
|
|
||||||
resp.Bsize = blockSize // Block size
|
|
||||||
resp.Namelen = 255 // Maximum file name length?
|
|
||||||
resp.Frsize = blockSize // Fragment size, smallest addressable data size in the file system.
|
|
||||||
*/
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user