5 CacheInfo::CacheInfo(CacheInfoMgr
*_cim
, WvStringParm _path
, bool _root
)
6 : path(_path
), root(_root
), uptodate(0), famid(0), child_count(0), cim(_cim
)
8 cim
->fi_by_path
.add(this, root
);
12 CacheInfo::~CacheInfo()
14 if (!root
&& uptodate
& FILEMASK
)
15 cim
->get_fileinfo(getdirname(path
))->remove_child();
18 cim
->fam
._unmonitor(famid
);
20 cim
->fi_by_path
.remove(this);
24 void CacheInfo::mark_uptodate(uint8 _uptodate
)
26 if (root
|| _uptodate
& DIRMASK
&& uptodate
& ~DIRMASK
)
29 fprintf(stderr
, "monitoring listing for %s\n", path
.cstr());
30 famid
= famid
? famid
: cim
->fam
._monitordir(&path
);
33 if (_uptodate
& FILEMASK
&& uptodate
& ~FILEMASK
)
35 fprintf(stderr
, "monitoring attributes for %s\n", path
.cstr());
37 cim
->get_fileinfo(getdirname(path
))->add_child();
39 famid
= famid
? famid
: cim
->fam
._monitordir(&path
);
43 uptodate
|= _uptodate
;
47 bool CacheInfo::is_uptodate(uint8 _uptodate
)
49 return uptodate
& _uptodate
;
53 void CacheInfo::invalidate(bool thisfile
)
57 if (!root
&& uptodate
& FILEMASK
)
59 cim
->get_fileinfo(getdirname(path
))->remove_child();
60 fprintf(stderr
, "invalidating attributes for %s\n", path
.cstr());
63 uptodate
&= ~FILEMASK
;
65 // means something *under* us changed
72 cim
->fam
._unmonitor(famid
);
73 fprintf(stderr
, "invalidating listing for %s\n", path
.cstr());
81 if (uptodate
== 0 && child_count
== 0 && !root
)
86 void CacheInfo::add_child()
91 famid
= cim
->fam
._monitordir(&path
);
95 void CacheInfo::remove_child()
99 if (child_count
== 0 && uptodate
== 0)
104 cim
->fam
._unmonitor(famid
);
112 CacheInfoMgr::CacheInfoMgr()
113 : fam(WvFamCallback(this, &CacheInfoMgr::fam_callback
)), fdmap(20)
115 new CacheInfo(this, "/", true);
119 CacheInfo
*CacheInfoMgr::get_fileinfo(WvStringParm path
)
121 CacheInfo
*fi
= fi_by_path
[path
];
123 return fi
? fi
: new CacheInfo(this, path
);
127 void CacheInfoMgr::cim_do_open(WvStringParm path
, int fd
)
133 void CacheInfoMgr::cim_do_close(int fd
)
139 void CacheInfoMgr::cim_mark_uptodate(WvStringParm path
, JobType jobtype
)
141 CacheInfo
*fi
= get_fileinfo(path
);
146 fi
->mark_uptodate(UTD_LIST
);
149 fi
->mark_uptodate(UTD_ATTR
);
152 fi
->mark_uptodate(UTD_LINK
);
155 assert(! "cim_mark_uptodate called with unknown jobtype");
161 void CacheInfoMgr::fam_callback(WvStringParm file
, WvFamEvent event
, bool fromdir
)
163 CacheInfo
*fi
= fi_by_path
[file
];
168 CacheInfo
*parent
= fi_by_path
[getdirname(file
)];
170 fi
->invalidate(true);
172 parent
->invalidate(false);