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 }
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 }
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 }