コード例 #1
0
ファイル: walk.go プロジェクト: datatonic/Dominator
func makeRegularInode(stat *syscall.Stat_t) *filesystem.RegularInode {
	var inode filesystem.RegularInode
	inode.Mode = filesystem.FileMode(stat.Mode)
	inode.Uid = stat.Uid
	inode.Gid = stat.Gid
	inode.MtimeSeconds = stat.Mtim.Sec
	inode.MtimeNanoSeconds = int32(stat.Mtim.Nsec)
	inode.Size = uint64(stat.Size)
	return &inode
}
コード例 #2
0
ファイル: sub.go プロジェクト: keep94/Dominator
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
}
コード例 #3
0
ファイル: walk.go プロジェクト: wxdublin/Dominator
func (fileSystem *FileSystem) getRegularInode(stat *syscall.Stat_t) (
	*filesystem.RegularInode, bool) {
	inode := fileSystem.RegularInodeTable[stat.Ino]
	new := false
	if inode == nil {
		var _inode filesystem.RegularInode
		inode = &_inode
		_inode.Mode = filesystem.FileMode(stat.Mode)
		_inode.Uid = stat.Uid
		_inode.Gid = stat.Gid
		_inode.MtimeSeconds = stat.Mtim.Sec
		_inode.MtimeNanoSeconds = int32(stat.Mtim.Nsec)
		_inode.Size = uint64(stat.Size)
		fileSystem.RegularInodeTable[stat.Ino] = inode
		new = true
	}
	return inode, new
}
コード例 #4
0
ファイル: decode.go プロジェクト: keep94/Dominator
func (decoderData *decoderData) addRegularFile(tarReader *tar.Reader,
	hasher Hasher, header *tar.Header, parent *filesystem.DirectoryInode,
	name string) error {
	var newInode filesystem.RegularInode
	newInode.Mode = filesystem.FileMode((header.Mode & ^syscall.S_IFMT) |
		syscall.S_IFREG)
	newInode.Uid = uint32(header.Uid)
	newInode.Gid = uint32(header.Gid)
	newInode.MtimeNanoSeconds = int32(header.ModTime.Nanosecond())
	newInode.MtimeSeconds = header.ModTime.Unix()
	newInode.Size = uint64(header.Size)
	if header.Size > 0 {
		var err error
		newInode.Hash, err = hasher.Hash(tarReader, uint64(header.Size))
		if err != nil {
			return err
		}
	}
	decoderData.addEntry(parent, header.Name, name, &newInode)
	return nil
}
コード例 #5
0
ファイル: decode.go プロジェクト: wxdublin/Dominator
func (decoderData *decoderData) addRegularFile(tarReader *tar.Reader,
	dataHandler DataHandler, header *tar.Header, parent *filesystem.Directory,
	name string) error {
	var newInode filesystem.RegularInode
	newInode.Mode = filesystem.FileMode((header.Mode & ^syscall.S_IFMT) |
		syscall.S_IFREG)
	newInode.Uid = uint32(header.Uid)
	newInode.Gid = uint32(header.Gid)
	newInode.MtimeNanoSeconds = int32(header.ModTime.Nanosecond())
	newInode.MtimeSeconds = header.ModTime.Unix()
	newInode.Size = uint64(header.Size)
	if header.Size > 0 {
		data, err := ioutil.ReadAll(tarReader)
		if err != nil {
			return errors.New("error reading file data" + err.Error())
		}
		if int64(len(data)) != header.Size {
			return errors.New(fmt.Sprintf(
				"failed to read file data, wanted: %d, got: %d bytes",
				header.Size, len(data)))
		}
		newInode.Hash, err = dataHandler.HandleData(data)
		if err != nil {
			return err
		}
	}
	decoderData.regularInodeTable[header.Name] = decoderData.nextInodeNumber
	decoderData.fileSystem.RegularInodeTable[decoderData.nextInodeNumber] =
		&newInode
	var newEntry filesystem.RegularFile
	newEntry.Name = name
	newEntry.InodeNumber = decoderData.nextInodeNumber
	parent.RegularFileList = append(parent.RegularFileList, &newEntry)
	decoderData.nextInodeNumber++
	return nil
}