Пример #1
0
func readFileSystem(name string) (*filesystem.FileSystem, error) {
	file, err := os.Open(name)
	if err != nil {
		return nil, err
	}
	defer file.Close()
	var fileSystem filesystem.FileSystem
	if err := gob.NewDecoder(file).Decode(&fileSystem); err != nil {
		return nil, err
	}
	fileSystem.RebuildInodePointers()
	return &fileSystem, nil
}
Пример #2
0
func spliceComputedFiles(fs *filesystem.FileSystem) error {
	if *computedFiles == "" {
		return nil
	}
	computedFileList, err := loadComputedFiles(*computedFiles)
	if err != nil {
		return errors.New("cannot load computed files list from: " +
			*computedFiles + ": " + err.Error())
	}
	filenameToInodeTable := fs.FilenameToInodeTable()
	inodeToFilenamesTable := fs.InodeToFilenamesTable()
	for _, computedFile := range computedFileList {
		inum, ok := filenameToInodeTable[computedFile.Filename]
		if !ok {
			return errors.New(computedFile.Filename + ": missing from image")
		}
		if filenames, ok := inodeToFilenamesTable[inum]; !ok {
			panic(computedFile.Filename + ": no corresponding list of files")
		} else if len(filenames) != 1 {
			return fmt.Errorf("%s: multiple inodes: %d", computedFile.Filename,
				len(filenames))
		}
		if inode, ok :=
			fs.InodeTable[inum].(*filesystem.ComputedRegularInode); ok {
			inode.Source = computedFile.Source
			continue
		}
		if oldInode, ok := fs.InodeTable[inum].(*filesystem.RegularInode); !ok {
			return fmt.Errorf("%s: type: %T is not a regular inode",
				computedFile.Filename, fs.InodeTable[inum])
		} else {
			newInode := new(filesystem.ComputedRegularInode)
			newInode.Mode = oldInode.Mode
			newInode.Uid = oldInode.Uid
			newInode.Gid = oldInode.Gid
			newInode.Source = computedFile.Source
			fs.InodeTable[inum] = newInode
		}
	}
	fs.ComputeTotalDataBytes()
	clearInodePointers(&fs.DirectoryInode, "")
	return fs.RebuildInodePointers()
}