Esempio n. 1
0
func compareRegularFile(request *subproto.UpdateRequest, state *state,
	subEntry interface{}, requiredRegularFile *filesystem.RegularFile,
	parentName string) {
	debugFilename := path.Join(parentName, requiredRegularFile.Name)
	if subRegularFile, ok := subEntry.(*filesystem.RegularFile); ok {
		if requiredInode, ok :=
			state.subInodeToRequiredInode[subRegularFile.InodeNumber]; ok {
			if requiredInode == requiredRegularFile.InodeNumber {
				//
				fmt.Printf("Different links: %s...\n", debugFilename) // HACK
			}
		} else {
			state.subInodeToRequiredInode[subRegularFile.InodeNumber] =
				requiredRegularFile.InodeNumber
		}
		sameMetadata := filesystem.CompareRegularInodesMetadata(
			subRegularFile.Inode(), requiredRegularFile.Inode(),
			os.Stdout)
		sameData := filesystem.CompareRegularInodesData(subRegularFile.Inode(),
			requiredRegularFile.Inode(), os.Stdout)
		if sameMetadata && sameData {
			return
		}
		fmt.Printf("Different rfile: %s...\n", debugFilename) // HACK
	} else {
		fmt.Printf("Add rfile: %s...\n", debugFilename) // HACK
	}
	// TODO(rgooch): Delete entry and replace.
}
Esempio n. 2
0
func scanRegularFile(file *filesystem.RegularFile, fileSystem *FileSystem,
	parentName string) error {
	myPathName := path.Join(parentName, file.Name)
	f, err := os.Open(path.Join(fileSystem.rootDirectoryName, myPathName))
	if err != nil {
		return err
	}
	reader := fileSystem.configuration.FsScanContext.NewReader(f)
	hash := sha512.New()
	io.Copy(hash, reader)
	f.Close()
	copy(file.Inode().Hash[:], hash.Sum(nil))
	return nil
}
Esempio n. 3
0
func addRegularFile(directory *filesystem.Directory,
	fileSystem, oldFS *FileSystem,
	name string, directoryPathName string, stat *syscall.Stat_t) error {
	inode, isNewInode := fileSystem.getRegularInode(stat)
	var file filesystem.RegularFile
	file.Name = name
	file.InodeNumber = stat.Ino
	file.SetInode(inode)
	if isNewInode {
		if inode.Size > 0 {
			err := scanRegularFile(&file, fileSystem, directoryPathName)
			if err != nil {
				return err
			}
		}
		if oldFS != nil && oldFS.RegularInodeTable != nil {
			if oldInode, found := oldFS.RegularInodeTable[stat.Ino]; found {
				if filesystem.CompareRegularInodes(inode, oldInode, nil) {
					inode = oldInode
					file.SetInode(inode)
					fileSystem.RegularInodeTable[stat.Ino] = inode
				}
			}
		}
	}
	directory.RegularFileList = append(directory.RegularFileList, &file)
	return nil
}
Esempio n. 4
0
func (decoderData *decoderData) addHardlink(header *tar.Header,
	parent *filesystem.Directory, name string) error {
	header.Linkname = normaliseFilename(header.Linkname)
	if inum, ok := decoderData.regularInodeTable[header.Linkname]; ok {
		var newEntry filesystem.RegularFile
		newEntry.Name = name
		newEntry.InodeNumber = inum
		parent.RegularFileList = append(parent.RegularFileList, &newEntry)
	} else if inum, ok := decoderData.symlinkInodeTable[header.Linkname]; ok {
		var newEntry filesystem.Symlink
		newEntry.Name = name
		newEntry.InodeNumber = inum
		parent.SymlinkList = append(parent.SymlinkList, &newEntry)
	} else if inum, ok := decoderData.inodeTable[header.Linkname]; ok {
		var newEntry filesystem.File
		newEntry.Name = name
		newEntry.InodeNumber = inum
		parent.FileList = append(parent.FileList, &newEntry)
	} else {
		return errors.New(fmt.Sprintf("missing hardlink target: %s",
			header.Linkname))
	}
	return nil
}
Esempio n. 5
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
}