Ejemplo n.º 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
}
Ejemplo n.º 2
0
func (c *connection) lastHelpful() time.Time {
	lasts := []time.Time{c.lastUsefulChunkReceived}
	if c.t.seeding() {
		lasts = append(lasts, c.lastChunkSent)
	}
	return missinggo.Max(time.Time.Before, slices.ToEmptyInterface(lasts)...).(time.Time)
}