Пример #1
0
func (sub *Sub) processFileUpdates() bool {
	haveUpdates := false
	for {
		image := sub.requiredImage
		if image != nil && sub.computedInodes == nil {
			sub.computedInodes = make(map[string]*filesystem.RegularInode)
			sub.busyFlagMutex.Lock()
			if sub.deleting {
				sub.busyFlagMutex.Unlock()
				return false
			}
			sub.herd.computedFilesManager.Update(
				filegenclient.Machine{sub.mdb, sub.getComputedFiles(image)})
			sub.busyFlagMutex.Unlock()
		}
		select {
		case fileInfos := <-sub.fileUpdateChannel:
			if image == nil {
				continue
			}
			filenameToInodeTable := image.FileSystem.FilenameToInodeTable()
			for _, fileInfo := range fileInfos {
				inum, ok := filenameToInodeTable[fileInfo.Pathname]
				if !ok {
					continue
				}
				genericInode, ok := image.FileSystem.InodeTable[inum]
				if !ok {
					continue
				}
				cInode, ok := genericInode.(*filesystem.ComputedRegularInode)
				if !ok {
					continue
				}
				rInode := new(filesystem.RegularInode)
				rInode.Mode = cInode.Mode
				rInode.Uid = cInode.Uid
				rInode.Gid = cInode.Gid
				rInode.MtimeSeconds = -1 // The time is set during the compute.
				rInode.Size = fileInfo.Length
				rInode.Hash = fileInfo.Hash
				sub.computedInodes[fileInfo.Pathname] = rInode
				haveUpdates = true
			}
		default:
			return haveUpdates
		}
	}
	return haveUpdates
}