modfile: improve directory path detection and error text consistency

An error text suggests a directory path needs to start with ./ or ../
if it's a relative path, but in reality relative paths with .\ and ..\
prefix (such as those that are used on Windows) are also accepted.

Furthermore, a relative path like ./ or ../ is fine, as are ./. and
../., but the cleaner and shorter equivalent relative paths . and ..
are reported as if they're not directory paths (even though a module
path cannot consist of nothing but dots).

Fix those inconsistencies and make IsDirectoryPath report true on "."
and ".." paths as expected, and make its documentation clear that
a path like "sub/dir", despite being a relative path, is interpreted
as a module path.

For golang/go#60572.

Change-Id: I8fa4a2c66bc83a1ccafc453b96f3bb33dc222cd1
Reviewed-on: https://go-review.googlesource.com/c/mod/+/500335
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 file changed
tree: 0829030bc3e1ff1d47740fdd66de8380cec79360
  1. gosumcheck/
  2. internal/
  3. modfile/
  4. module/
  5. semver/
  6. sumdb/
  7. zip/
  8. codereview.cfg
  9. go.mod
  10. go.sum
  11. LICENSE
  12. PATENTS
  13. README.md
README.md

mod

PkgGoDev

This repository holds packages for writing tools that work directly with Go module mechanics. That is, it is for direct manipulation of Go modules themselves.

It is NOT about supporting general development tools that need to do things like load packages in module mode. That use case, where modules are incidental rather than the focus, should remain in x/tools, specifically x/tools/go/packages.

The specific case of loading packages should still be done by invoking the go command, which remains the single point of truth for package loading algorithms.