mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
Remove the NEXT-RELEASE.md symlink.
GitHub displays symlinks simply as the path of the destination, meaning that we can't just link to it for the notes of the next release.
This commit is contained in:
parent
15163a9459
commit
b1d50754e2
|
@ -38,10 +38,13 @@ or compiled, even if it is not executed:
|
|||
- Iterating over certain list slices no longer crash Elvish
|
||||
([#1287](https://b.elv.sh/1287)).
|
||||
|
||||
- The `path:is-dir` and `path:is-regular` commands no longer follow symlinks,
|
||||
as advertised in the documentation.
|
||||
- The `path:is-dir` and `path:is-regular` commands default behavior no longer
|
||||
follows a final symlink as advertised in the original documentation. A
|
||||
`&follow-symlink` option has been added to get the old, undocumented,
|
||||
behavior since it can be useful and avoids the need to use
|
||||
`path:eval-symlinks` to transform the path in common use cases.
|
||||
|
||||
- Evaluating `~username` no longer appends a slash
|
||||
* Evaluating `~username` no longer appends a slash
|
||||
([#1246](https://b.elv.sh/1246)).
|
||||
|
||||
# Notable new features
|
||||
|
|
|
@ -136,13 +136,15 @@ var fns = map[string]interface{}{
|
|||
//elvdoc:fn is-dir
|
||||
//
|
||||
// ```elvish
|
||||
// is-dir $path
|
||||
// is-dir &follow-symlink=$false $path
|
||||
// ```
|
||||
//
|
||||
// Outputs `$true` if the path resolves to a directory. If the final element of the path is a
|
||||
// symlink, even if it points to a directory, it still outputs `$false` since a symlink is not a
|
||||
// directory. Use [`eval-symlinks`](#patheval-symlinks) on the path first if you don't care if the
|
||||
// final element is a symlink.
|
||||
// directory. Setting option `&follow-symlink` to true will cause the last element of the path, if
|
||||
// it is a symlink, to be resolved before doing the test.
|
||||
//
|
||||
// @cf eval-symlinks
|
||||
//
|
||||
// ```elvish-transcript
|
||||
// ~> touch not-a-dir
|
||||
|
@ -152,21 +154,33 @@ var fns = map[string]interface{}{
|
|||
// ▶ true
|
||||
// ```
|
||||
|
||||
func isDir(path string) bool {
|
||||
fi, err := os.Lstat(path)
|
||||
type isOpts struct{ FollowSymlink bool }
|
||||
|
||||
func (opts *isOpts) SetDefaultOptions() {}
|
||||
|
||||
func isDir(opts isOpts, path string) bool {
|
||||
var fi os.FileInfo
|
||||
var err error
|
||||
if opts.FollowSymlink {
|
||||
fi, err = os.Stat(path)
|
||||
} else {
|
||||
fi, err = os.Lstat(path)
|
||||
}
|
||||
return err == nil && fi.Mode().IsDir()
|
||||
}
|
||||
|
||||
//elvdoc:fn is-regular
|
||||
//
|
||||
// ```elvish
|
||||
// is-regular $path
|
||||
// is-regular &follow-symlink=$false $path
|
||||
// ```
|
||||
//
|
||||
// Outputs `$true` if the path resolves to a regular file. If the final element of the path is a
|
||||
// symlink, even if it points to a regular file, it still outputs `$false` since a symlink is not a
|
||||
// regular file. Use [`eval-symlinks`](#patheval-symlinks) on the path first if you don't care if
|
||||
// the final element is a symlink.
|
||||
// regular file. Setting option `&follow-symlink` to true will cause the last element of the path,
|
||||
// if it is a symlink, to be resolved before doing the test.
|
||||
//
|
||||
// @cf eval-symlinks
|
||||
//
|
||||
// ```elvish-transcript
|
||||
// ~> touch not-a-dir
|
||||
|
@ -176,8 +190,14 @@ func isDir(path string) bool {
|
|||
// ▶ false
|
||||
// ```
|
||||
|
||||
func isRegular(path string) bool {
|
||||
fi, err := os.Lstat(path)
|
||||
func isRegular(opts isOpts, path string) bool {
|
||||
var fi os.FileInfo
|
||||
var err error
|
||||
if opts.FollowSymlink {
|
||||
fi, err = os.Stat(path)
|
||||
} else {
|
||||
fi, err = os.Lstat(path)
|
||||
}
|
||||
return err == nil && fi.Mode().IsRegular()
|
||||
}
|
||||
|
||||
|
|
|
@ -13,12 +13,15 @@ import (
|
|||
|
||||
var testDir = testutil.Dir{
|
||||
"d1": testutil.Dir{
|
||||
"f": testutil.Symlink{Target: filepath.Join("d2", "f")},
|
||||
"d2": testutil.Dir{
|
||||
"empty": "",
|
||||
"f": "",
|
||||
"g": testutil.Symlink{Target: "f"},
|
||||
},
|
||||
// These symlink definitions must occur after definition of their targets because on Windows
|
||||
// the behavior of the os.Symlink function depends on the nature of the target; unlike UNIX.
|
||||
"d": testutil.Symlink{"d2"},
|
||||
"f": testutil.Symlink{filepath.Join("d2", "f")},
|
||||
},
|
||||
"s1": testutil.Symlink{Target: filepath.Join("d1", "d2")},
|
||||
}
|
||||
|
@ -54,7 +57,8 @@ func TestPath(t *testing.T) {
|
|||
That(`path:is-abs a/b/s`).Puts(false),
|
||||
That(`path:is-abs `+absPath).Puts(true),
|
||||
That(`path:eval-symlinks d1/d2`).Puts(filepath.Join("d1", "d2")),
|
||||
That(`path:eval-symlinks d1/d2/f`).Puts(filepath.Join("d1", "d2", "f")),
|
||||
That(`path:eval-symlinks d1/d`).Puts(filepath.Join("d1", "d2")),
|
||||
That(`path:eval-symlinks d1/d/f`).Puts(filepath.Join("d1", "d2", "f")),
|
||||
That(`path:eval-symlinks s1`).Puts(filepath.Join("d1", "d2")),
|
||||
That(`path:eval-symlinks d1/f`).Puts(filepath.Join("d1", "d2", "f")),
|
||||
That(`path:eval-symlinks s1/g`).Puts(filepath.Join("d1", "d2", "f")),
|
||||
|
@ -65,9 +69,19 @@ func TestPath(t *testing.T) {
|
|||
That(`path:is-dir a/b/s`).Puts(false),
|
||||
That(`path:is-dir `+tmpdir).Puts(true),
|
||||
That(`path:is-dir s1`).Puts(false),
|
||||
That(`path:is-dir d1/d`).Puts(false),
|
||||
That(`path:is-dir d1/d &follow-symlink`).Puts(true),
|
||||
That(`path:is-dir d1/d/does-not-exist`).Puts(false),
|
||||
That(`path:is-dir d1/d/does-not-exist &follow-symlink`).Puts(false),
|
||||
That(`path:is-dir d1/f`).Puts(false),
|
||||
That(`path:is-dir d1/f &follow-symlink`).Puts(false),
|
||||
|
||||
That(`path:is-regular a/b/s`).Puts(false),
|
||||
That(`path:is-regular `+tmpdir).Puts(false),
|
||||
That(`path:is-regular d1/f`).Puts(false),
|
||||
That(`path:is-regular d1/f &follow-symlink`).Puts(true),
|
||||
That(`path:is-regular d1/f/does-not-exist`).Puts(false),
|
||||
That(`path:is-regular d1/f/does-not-exist &follow-symlink`).Puts(false),
|
||||
That(`path:is-regular d1/d2/f`).Puts(true),
|
||||
That(`path:is-regular s1/f`).Puts(true),
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user