func scanSymlink(symlink *filesystem.Symlink, fileSystem *FileSystem, parentName string) error { myPathName := path.Join(parentName, symlink.Name) target, err := os.Readlink(path.Join(fileSystem.rootDirectoryName, myPathName)) if err != nil { return err } symlink.Inode().Symlink = target return nil }
func (decoderData *decoderData) addSymlink(header *tar.Header, parent *filesystem.Directory, name string) error { var newInode filesystem.SymlinkInode newInode.Uid = uint32(header.Uid) newInode.Gid = uint32(header.Gid) newInode.Symlink = header.Linkname decoderData.symlinkInodeTable[header.Name] = decoderData.nextInodeNumber decoderData.fileSystem.SymlinkInodeTable[decoderData.nextInodeNumber] = &newInode var newEntry filesystem.Symlink newEntry.Name = name newEntry.InodeNumber = decoderData.nextInodeNumber parent.SymlinkList = append(parent.SymlinkList, &newEntry) decoderData.nextInodeNumber++ return nil }
func addSymlink(directory *filesystem.Directory, fileSystem, oldFS *FileSystem, name string, directoryPathName string, stat *syscall.Stat_t) error { inode, isNewInode := fileSystem.getSymlinkInode(stat) var symlink filesystem.Symlink symlink.Name = name symlink.InodeNumber = stat.Ino symlink.SetInode(inode) if isNewInode { err := scanSymlink(&symlink, fileSystem, directoryPathName) if err != nil { return err } if oldFS != nil && oldFS.SymlinkInodeTable != nil { if oldInode, found := oldFS.SymlinkInodeTable[stat.Ino]; found { if filesystem.CompareSymlinkInodes(inode, oldInode, nil) { inode = oldInode symlink.SetInode(inode) fileSystem.SymlinkInodeTable[stat.Ino] = inode } } } } directory.SymlinkList = append(directory.SymlinkList, &symlink) 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 compareSymlink(request *subproto.UpdateRequest, state *state, subEntry interface{}, requiredSymlink *filesystem.Symlink, parentName string) { debugFilename := path.Join(parentName, requiredSymlink.Name) if subSymlink, ok := subEntry.(*filesystem.Symlink); ok { if requiredInode, ok := state.subInodeToRequiredInode[subSymlink.InodeNumber]; ok { if requiredInode != requiredSymlink.InodeNumber { fmt.Printf("Different links: %s...\n", debugFilename) // HACK } } else { state.subInodeToRequiredInode[subSymlink.InodeNumber] = requiredSymlink.InodeNumber } if filesystem.CompareSymlinkInodes(subSymlink.Inode(), requiredSymlink.Inode(), os.Stdout) { return } fmt.Printf("Different symlink: %s...\n", debugFilename) // HACK } else { fmt.Printf("Add symlink: %s...\n", debugFilename) // HACK } // TODO(rgooch): Delete entry and replace. }