Exemple #1
0
func makeRegularInode(fullPathname string, inode *filesystem.RegularInode,
	multiplyUsedObjects map[hash.Hash]uint64) {
	var err error
	if inode.Size > 0 {
		objectPathname := path.Join(objectsDir,
			objectcache.HashToFilename(inode.Hash))
		numCopies := multiplyUsedObjects[inode.Hash]
		if numCopies > 1 {
			numCopies--
			objectPathname += strings.Repeat("~", int(numCopies))
			if numCopies < 2 {
				delete(multiplyUsedObjects, inode.Hash)
			}
		}
		err = os.Rename(objectPathname, fullPathname)
	} else {
		_, err = os.Create(fullPathname)
	}
	if err != nil {
		logger.Println(err)
		return
	}
	if err := inode.WriteMetadata(fullPathname); err != nil {
		logger.Println(err)
	} else {
		if inode.Size > 0 {
			logger.Printf("Made inode: %s from: %x\n", fullPathname, inode.Hash)
		} else {
			logger.Printf("Made empty inode: %s\n", fullPathname)
		}
	}
}
func setComputedFileMtime(requiredInode *filesystem.RegularInode,
	subEntry *filesystem.DirectoryEntry) {
	if requiredInode.MtimeSeconds >= 0 {
		return
	}
	if subEntry != nil {
		subInode := subEntry.Inode()
		if subInode, ok := subInode.(*filesystem.RegularInode); ok {
			if requiredInode.Hash == subInode.Hash {
				requiredInode.MtimeNanoSeconds = subInode.MtimeNanoSeconds
				requiredInode.MtimeSeconds = subInode.MtimeSeconds
				return
			}
		}
	}
	requiredInode.MtimeSeconds = time.Now().Unix()
}
Exemple #3
0
func makeRegularInode(fullPathname string,
	inode *filesystem.RegularInode, multiplyUsedObjects map[hash.Hash]uint64,
	objectsDir string, logger *log.Logger) error {
	var objectPathname string
	if inode.Size > 0 {
		objectPathname = path.Join(objectsDir,
			objectcache.HashToFilename(inode.Hash))
		numCopies := multiplyUsedObjects[inode.Hash]
		if numCopies > 1 {
			numCopies--
			objectPathname += fmt.Sprintf("~%d~", numCopies)
			if numCopies < 2 {
				delete(multiplyUsedObjects, inode.Hash)
			} else {
				multiplyUsedObjects[inode.Hash] = numCopies
			}
		}
	} else {
		objectPathname = fmt.Sprintf("%s.empty.%d", fullPathname, os.Getpid())
		if file, err := os.OpenFile(objectPathname,
			os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600); err != nil {
			return err
		} else {
			file.Close()
		}
	}
	if err := fsutil.ForceRename(objectPathname, fullPathname); err != nil {
		logger.Println(err)
		return err
	}
	if err := inode.WriteMetadata(fullPathname); err != nil {
		logger.Println(err)
		return err
	} else {
		if inode.Size > 0 {
			logger.Printf("Made inode: %s from: %x\n",
				fullPathname, inode.Hash)
		} else {
			logger.Printf("Made empty inode: %s\n", fullPathname)
		}
	}
	return nil
}
Exemple #4
0
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
}
Exemple #5
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
}
Exemple #6
0
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
}
Exemple #7
0
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
}
Exemple #8
0
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
}