func (decoderData *decoderData) addFile(header *tar.Header, parent *filesystem.Directory, name string) error { var newInode filesystem.Inode if header.Typeflag == tar.TypeChar { newInode.Mode = filesystem.FileMode((header.Mode & ^syscall.S_IFMT) | syscall.S_IFCHR) } else if header.Typeflag == tar.TypeBlock { newInode.Mode = filesystem.FileMode((header.Mode & ^syscall.S_IFMT) | syscall.S_IFBLK) } else if header.Typeflag == tar.TypeFifo { newInode.Mode = filesystem.FileMode((header.Mode & ^syscall.S_IFMT) | syscall.S_IFIFO) } else { return errors.New(fmt.Sprintf("unsupported type: %v", header.Typeflag)) } newInode.Uid = uint32(header.Uid) newInode.Gid = uint32(header.Gid) newInode.MtimeNanoSeconds = int32(header.ModTime.Nanosecond()) newInode.MtimeSeconds = header.ModTime.Unix() if header.Devminor > 255 { return errors.New(fmt.Sprintf("minor device number: %d too large", header.Devminor)) } newInode.Rdev = uint64(header.Devmajor<<8 | header.Devminor) decoderData.inodeTable[header.Name] = decoderData.nextInodeNumber decoderData.fileSystem.InodeTable[decoderData.nextInodeNumber] = &newInode var newEntry filesystem.File newEntry.Name = name newEntry.InodeNumber = decoderData.nextInodeNumber parent.FileList = append(parent.FileList, &newEntry) decoderData.nextInodeNumber++ return nil }
func addFile(directory *filesystem.Directory, fileSystem, oldFS *FileSystem, name string, directoryPathName string, stat *syscall.Stat_t) error { inode, isNewInode := fileSystem.getInode(stat) var file filesystem.File file.Name = name file.InodeNumber = stat.Ino file.SetInode(inode) if isNewInode { err := scanFile(&file, fileSystem, directoryPathName) if err != nil { return err } if oldFS != nil && oldFS.InodeTable != nil { if oldInode, found := oldFS.InodeTable[stat.Ino]; found { if filesystem.CompareInodes(inode, oldInode, nil) { inode = oldInode file.SetInode(inode) fileSystem.InodeTable[stat.Ino] = inode } } } } directory.FileList = append(directory.FileList, &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 }