예제 #1
0
파일: decode.go 프로젝트: keep94/Dominator
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)
}
예제 #2
0
파일: decode.go 프로젝트: keep94/Dominator
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
}
예제 #3
0
파일: walk.go 프로젝트: datatonic/Dominator
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
	}
}
예제 #4
0
// Returns true if there is a failure due to missing computed files.
func (sub *Sub) compareDirectories(request *subproto.UpdateRequest,
	subDirectory, requiredDirectory *filesystem.DirectoryInode,
	myPathName string, deleteMissingComputedFiles bool,
	logger *log.Logger) bool {
	// First look for entries that should be deleted.
	if sub.filter != nil && subDirectory != nil {
		for name := range subDirectory.EntriesByName {
			pathname := path.Join(myPathName, name)
			if sub.filter.Match(pathname) {
				continue
			}
			if _, ok := requiredDirectory.EntriesByName[name]; !ok {
				request.PathsToDelete = append(request.PathsToDelete, pathname)
			}
		}
	}
	for name, requiredEntry := range requiredDirectory.EntriesByName {
		pathname := path.Join(myPathName, name)
		if sub.filter != nil && sub.filter.Match(pathname) {
			continue
		}
		var subEntry *filesystem.DirectoryEntry
		if subDirectory != nil {
			if se, ok := subDirectory.EntriesByName[name]; ok {
				subEntry = se
			}
		}
		requiredInode := requiredEntry.Inode()
		if _, ok := requiredInode.(*filesystem.ComputedRegularInode); ok {
			// Replace with computed file.
			inode, ok := sub.ComputedInodes[pathname]
			if !ok {
				if deleteMissingComputedFiles {
					if subEntry != nil {
						request.PathsToDelete = append(request.PathsToDelete,
							pathname)
					}
					continue
				}
				logger.Printf(
					"compareDirectories(%s): missing computed file: %s\n",
					sub, pathname)
				return true
			}
			setComputedFileMtime(inode, subEntry)
			newEntry := new(filesystem.DirectoryEntry)
			newEntry.Name = name
			newEntry.InodeNumber = requiredEntry.InodeNumber
			newEntry.SetInode(inode)
			requiredEntry = newEntry
		}
		if subEntry == nil {
			sub.addEntry(request, requiredEntry, pathname)
		} else {
			sub.compareEntries(request, subEntry, requiredEntry, pathname)
		}
		// If a directory: descend (possibly with the directory for the sub).
		if requiredInode, ok := requiredInode.(*filesystem.DirectoryInode); ok {
			var subInode *filesystem.DirectoryInode
			if subEntry != nil {
				if si, ok := subEntry.Inode().(*filesystem.DirectoryInode); ok {
					subInode = si
				}
			}
			sub.compareDirectories(request, subInode, requiredInode, pathname,
				deleteMissingComputedFiles, logger)
		}
	}
	return false
}