Skip to content

Mounted: add path resolution #27

Description

@kolyshkin

The argument to mount.Mounted call needs to be an absolute path with symlinks resolved and cleaned (otherwise it won't match the path in mountinfo). Currently, it is a caller's duty to make sure the path is prepared. I am thinking into moving this functionality into the library, because

  1. if the path is already prepared, this won't affect performance much (it's a few stat(2) syscalls);
  2. if the path is not prepared and is resolved correctly, we avoid "false negative".

The implementation of 'resolve' is something like this:

        if realPath, err = filepath.Abs(path); err != nil {
                return false, fmt.Errorf("unable to get absolute path for %q: %w", path, err)
        }
        if realPath, err = filepath.EvalSymlinks(realPath); err != nil {
                return false, fmt.Errorf("failed to canonicalise path for %q: %w", path, err)
        }
        if _, err := os.Stat(realPath); err != nil {
                return false, fmt.Errorf(err, "failed to stat target %q of %q: %w", realPath, path, err)
        }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions