Beispiel #1
0
// Triggers the item for path to be updated. If access is non-zero, set the
// item's access time to that value, otherwise deduce it appropriately.
func (me *Cache) statItem(path string, access time.Time) {
	info, ok := me.removeInfo(path)
	fi, err := os.Stat(me.realpath(path))
	if os.IsNotExist(err) {
		return
	}
	if err != nil {
		panic(err)
	}
	if !ok {
		info.Path = path
	}
	if !access.IsZero() {
		info.Accessed = access
	}
	if info.Accessed.IsZero() {
		info.Accessed = missinggo.Max(
			func(left, right time.Time) bool { return left.Before(right) },
			missinggo.FileInfoAccessTime(fi),
			fi.ModTime(),
		).(time.Time)
	}
	info.Size = fi.Size()
	me.filled += info.Size
	me.insertItem(info)
	me.paths[path] = info
}
Beispiel #2
0
func lastTime(fi os.FileInfo) (ret time.Time) {
	ret = fi.ModTime()
	atime := missinggo.FileInfoAccessTime(fi)
	if atime.After(ret) {
		ret = atime
	}
	return
}
Beispiel #3
0
// Triggers the item for path to be updated. If access is non-zero, set the
// item's access time to that value, otherwise deduce it appropriately.
func (me *Cache) statItem(path string, access time.Time) {
	info := me.removeInfo(path)
	fi, err := os.Stat(me.realpath(path))
	if os.IsNotExist(err) {
		return
	}
	if err != nil {
		panic(err)
	}
	if info == nil {
		info = &ItemInfo{
			Path: path,
		}
	}
	if !access.IsZero() {
		info.Accessed = access
	}
	if info.Accessed.IsZero() {
		info.Accessed = missinggo.FileInfoAccessTime(fi)
	}
	info.Size = fi.Size()
	me.filled += info.Size
	me.paths[path] = me.insertItem(info)
}