Exemple #1
0
func (decoderData *decoderData) addEntry(parent *filesystem.DirectoryInode,
	fullName, name string, inode filesystem.GenericInode) {
	var newEntry filesystem.DirectoryEntry
	newEntry.Name = name
	newEntry.InodeNumber = decoderData.nextInodeNumber
	newEntry.SetInode(inode)
	parent.EntryList = append(parent.EntryList, &newEntry)
	decoderData.addInode(fullName, inode)
}
Exemple #2
0
func sortDirectory(directory *filesystem.DirectoryInode) {
	var entryList directoryEntryList
	entryList = directory.EntryList
	sort.Sort(entryList)
	directory.EntryList = entryList
	// Recurse through directories.
	for _, dirent := range directory.EntryList {
		if inode, ok := dirent.Inode().(*filesystem.DirectoryInode); ok {
			sortDirectory(inode)
		}
	}
}
Exemple #3
0
func (decoderData *decoderData) addHardlink(header *tar.Header,
	parent *filesystem.DirectoryInode, name string) error {
	header.Linkname = normaliseFilename(header.Linkname)
	if inum, ok := decoderData.inodeTable[header.Linkname]; ok {
		var newEntry filesystem.DirectoryEntry
		newEntry.Name = name
		newEntry.InodeNumber = inum
		parent.EntryList = append(parent.EntryList, &newEntry)
	} else {
		return errors.New(fmt.Sprintf("missing hardlink target: %s",
			header.Linkname))
	}
	return nil
}
Exemple #4
0
func scanDirectory(directory, oldDirectory *filesystem.DirectoryInode,
	fileSystem, oldFS *FileSystem, myPathName string) (error, bool) {
	file, err := os.Open(path.Join(fileSystem.rootDirectoryName, myPathName))
	if err != nil {
		return err, false
	}
	names, err := file.Readdirnames(-1)
	file.Close()
	if err != nil {
		return err, false
	}
	sort.Strings(names)
	entryList := make([]*filesystem.DirectoryEntry, 0, len(names))
	var copiedDirents int
	for _, name := range names {
		if directory == &fileSystem.DirectoryInode && name == ".subd" {
			continue
		}
		filename := path.Join(myPathName, name)
		if fileSystem.configuration.ScanFilter.Match(filename) {
			continue
		}
		var stat syscall.Stat_t
		err := syscall.Lstat(path.Join(fileSystem.rootDirectoryName, filename),
			&stat)
		if err != nil {
			if err == syscall.ENOENT {
				continue
			}
			return err, false
		}
		if stat.Dev != fileSystem.dev {
			continue
		}
		if checkScanDisableRequest() {
			return errors.New("DisableScan"), false
		}
		myGC()
		dirent := new(filesystem.DirectoryEntry)
		dirent.Name = name
		dirent.InodeNumber = stat.Ino
		var oldDirent *filesystem.DirectoryEntry
		if oldDirectory != nil {
			index := len(entryList)
			if len(oldDirectory.EntryList) > index &&
				oldDirectory.EntryList[index].Name == name {
				oldDirent = oldDirectory.EntryList[index]
			}
		}
		if stat.Mode&syscall.S_IFMT == syscall.S_IFDIR {
			err = addDirectory(dirent, oldDirent, fileSystem, oldFS, myPathName,
				&stat)
		} else if stat.Mode&syscall.S_IFMT == syscall.S_IFREG {
			err = addRegularFile(dirent, fileSystem, oldFS, myPathName, &stat)
		} else if stat.Mode&syscall.S_IFMT == syscall.S_IFLNK {
			err = addSymlink(dirent, fileSystem, oldFS, myPathName, &stat)
		} else if stat.Mode&syscall.S_IFMT == syscall.S_IFSOCK {
			continue
		} else {
			err = addSpecialFile(dirent, fileSystem, oldFS, &stat)
		}
		if err != nil {
			if err == syscall.ENOENT {
				continue
			}
			return err, false
		}
		if oldDirent != nil && *dirent == *oldDirent {
			dirent = oldDirent
			copiedDirents++
		}
		entryList = append(entryList, dirent)
	}
	if oldDirectory != nil && len(entryList) == copiedDirents &&
		len(entryList) == len(oldDirectory.EntryList) {
		directory.EntryList = oldDirectory.EntryList
		return nil, true
	} else {
		directory.EntryList = entryList
		return nil, false
	}
}