mirror of
https://github.com/rclone/rclone.git
synced 2025-01-26 16:20:23 +01:00
mountlib: add parent and entry to Dir
This commit is contained in:
parent
0bb84efe75
commit
c6cd2a5280
@ -24,17 +24,21 @@ type Dir struct {
|
|||||||
fsys *FS
|
fsys *FS
|
||||||
inode uint64 // inode number
|
inode uint64 // inode number
|
||||||
f fs.Fs
|
f fs.Fs
|
||||||
|
parent *Dir // parent, nil for root
|
||||||
path string
|
path string
|
||||||
modTime time.Time
|
modTime time.Time
|
||||||
|
entry fs.Directory
|
||||||
mu sync.Mutex // protects the following
|
mu sync.Mutex // protects the following
|
||||||
read time.Time // time directory entry last read
|
read time.Time // time directory entry last read
|
||||||
items map[string]*DirEntry // NB can be nil when directory not read yet
|
items map[string]*DirEntry // NB can be nil when directory not read yet
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDir(fsys *FS, f fs.Fs, fsDir fs.Directory) *Dir {
|
func newDir(fsys *FS, f fs.Fs, parent *Dir, fsDir fs.Directory) *Dir {
|
||||||
return &Dir{
|
return &Dir{
|
||||||
fsys: fsys,
|
fsys: fsys,
|
||||||
f: f,
|
f: f,
|
||||||
|
parent: parent,
|
||||||
|
entry: fsDir,
|
||||||
path: fsDir.Remote(),
|
path: fsDir.Remote(),
|
||||||
modTime: fsDir.ModTime(),
|
modTime: fsDir.ModTime(),
|
||||||
inode: NewInode(),
|
inode: NewInode(),
|
||||||
@ -138,6 +142,8 @@ func (d *Dir) walk(absPath string, fun func(*Dir)) {
|
|||||||
// reading everything again
|
// reading everything again
|
||||||
func (d *Dir) rename(newParent *Dir, fsDir fs.Directory) {
|
func (d *Dir) rename(newParent *Dir, fsDir fs.Directory) {
|
||||||
d.ForgetAll()
|
d.ForgetAll()
|
||||||
|
d.parent = newParent
|
||||||
|
d.entry = fsDir
|
||||||
d.path = fsDir.Remote()
|
d.path = fsDir.Remote()
|
||||||
d.modTime = fsDir.ModTime()
|
d.modTime = fsDir.ModTime()
|
||||||
d.read = time.Time{}
|
d.read = time.Time{}
|
||||||
@ -219,7 +225,7 @@ func (d *Dir) _readDir() error {
|
|||||||
}
|
}
|
||||||
d.items[name] = &DirEntry{
|
d.items[name] = &DirEntry{
|
||||||
Obj: dir,
|
Obj: dir,
|
||||||
Node: newDir(d.fsys, d.f, dir),
|
Node: newDir(d.fsys, d.f, d, dir),
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
err = errors.Errorf("unknown type %T", item)
|
err = errors.Errorf("unknown type %T", item)
|
||||||
@ -350,7 +356,7 @@ func (d *Dir) Mkdir(name string) (*Dir, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
fsDir := fs.NewDir(path, time.Now())
|
fsDir := fs.NewDir(path, time.Now())
|
||||||
dir := newDir(d.fsys, d.f, fsDir)
|
dir := newDir(d.fsys, d.f, d, fsDir)
|
||||||
d.addObject(fsDir, dir)
|
d.addObject(fsDir, dir)
|
||||||
// fs.Debugf(path, "Dir.Mkdir OK")
|
// fs.Debugf(path, "Dir.Mkdir OK")
|
||||||
return dir, nil
|
return dir, nil
|
||||||
|
@ -69,7 +69,7 @@ func NewFS(f fs.Fs) *FS {
|
|||||||
}
|
}
|
||||||
fsys.dirCacheTime = DirCacheTime
|
fsys.dirCacheTime = DirCacheTime
|
||||||
|
|
||||||
fsys.root = newDir(fsys, f, fsDir)
|
fsys.root = newDir(fsys, f, nil, fsDir)
|
||||||
|
|
||||||
if PollInterval > 0 {
|
if PollInterval > 0 {
|
||||||
fsys.PollChanges(PollInterval)
|
fsys.PollChanges(PollInterval)
|
||||||
|
Loading…
Reference in New Issue
Block a user