Exemple #1
0
// Lookup implements the fs.NodeRequestLookuper interface.
func (fl *FolderList) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.LookupResponse) (node fs.Node, err error) {
	fl.fs.log.CDebugf(ctx, "FL Lookup %s", req.Name)
	defer func() {
		fl.reportErr(ctx, libkbfs.ReadMode,
			libkbfs.CanonicalTlfName(req.Name), err)
	}()
	fl.mu.Lock()
	defer fl.mu.Unlock()

	specialNode := handleSpecialFile(req.Name, fl.fs, resp)
	if specialNode != nil {
		return specialNode, nil
	}

	if child, ok := fl.folders[req.Name]; ok {
		return child, nil
	}

	// Shortcut for dreaded extraneous OSX finder lookups
	if strings.HasPrefix(req.Name, "._") {
		return nil, fuse.ENOENT
	}

	h, err := libkbfs.ParseTlfHandle(
		ctx, fl.fs.config.KBPKI(), req.Name, fl.public,
		fl.fs.config.SharingBeforeSignupEnabled())
	switch err := err.(type) {
	case nil:
		// No error.
		break

	case libkbfs.TlfNameNotCanonical:

		// Only permit Aliases to targets that contain no errors.
		if !fl.isValidAliasTarget(ctx, err.NameToTry) {
			fl.fs.log.CDebugf(ctx, "FL Refusing alias to non-valid target %q", err.NameToTry)
			return nil, fuse.ENOENT
		}
		// Non-canonical name.
		n := &Alias{
			canon: err.NameToTry,
		}
		return n, nil

	case libkbfs.NoSuchNameError, libkbfs.BadTLFNameError:
		// Invalid public TLF.
		return nil, fuse.ENOENT

	default:
		// Some other error.
		return nil, err
	}

	child := newTLF(fl, h)
	fl.folders[req.Name] = child
	return child, nil
}
Exemple #2
0
// Returns a nil node if p doesn't have type tlfPath.
func (p kbfsPath) getNode(ctx context.Context, config libkbfs.Config) (n libkbfs.Node, ei libkbfs.EntryInfo, err error) {
	if p.pathType != tlfPath {
		ei := libkbfs.EntryInfo{
			Type: libkbfs.Dir,
		}
		return nil, ei, nil
	}

	var h *libkbfs.TlfHandle
	name := p.tlfName
outer:
	for {
		h, err = libkbfs.ParseTlfHandle(
			ctx, config.KBPKI(), name, p.public,
			config.SharingBeforeSignupEnabled())
		switch err := err.(type) {
		case nil:
			// No error.
			break outer

		case libkbfs.TlfNameNotCanonical:
			// Non-canonical name, so try again.
			name = err.NameToTry

		default:
			// Some other error.
			return nil, libkbfs.EntryInfo{}, err
		}
	}

	n, ei, err =
		config.KBFSOps().GetOrCreateRootNode(
			ctx, h, libkbfs.MasterBranch)

	for _, component := range p.tlfComponents {
		cn, cei, err := config.KBFSOps().Lookup(ctx, n, component)
		if err != nil {
			return nil, libkbfs.EntryInfo{}, err
		}
		n = cn
		ei = cei
	}

	return n, ei, nil
}