v1.13.2
ADDED: * paths.RealPathJoin() and paths.RealPathJoinSys()
This commit is contained in:
parent
772324247a
commit
82f58d4fbf
@ -19,22 +19,23 @@
|
|||||||
package paths
|
package paths
|
||||||
|
|
||||||
import (
|
import (
|
||||||
`context`
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
`sort`
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
`sync`
|
"sync"
|
||||||
`time`
|
"time"
|
||||||
|
|
||||||
// "syscall"
|
// "syscall"
|
||||||
|
|
||||||
`github.com/djherbis/times`
|
"github.com/djherbis/times"
|
||||||
`r00t2.io/goutils/bitmask`
|
"r00t2.io/goutils/bitmask"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -221,6 +222,68 @@ func RealPath(path *string) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
RealPathJoin combines RealPath with (path).Join.
|
||||||
|
|
||||||
|
If dst is nil, then rootPath will be updated with the new value.
|
||||||
|
You probably don't want that.
|
||||||
|
*/
|
||||||
|
func RealPathJoin(rootPath, dst *string, subPaths ...string) (err error) {
|
||||||
|
|
||||||
|
var newPath string
|
||||||
|
var realDst *string
|
||||||
|
|
||||||
|
if err = RealPath(rootPath); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if dst == nil {
|
||||||
|
realDst = rootPath
|
||||||
|
} else {
|
||||||
|
realDst = dst
|
||||||
|
}
|
||||||
|
|
||||||
|
newPath = path.Join(append([]string{*rootPath}, subPaths...)...)
|
||||||
|
if err = RealPath(&newPath); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
*realDst = newPath
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
RealPathJoinSys combines RealPath with (path/filepath).Join.
|
||||||
|
|
||||||
|
If dst is nil, then path will be updated with the new value.
|
||||||
|
You probably don't want that.
|
||||||
|
*/
|
||||||
|
func RealPathJoinSys(path, dst *string, subPaths ...string) (err error) {
|
||||||
|
|
||||||
|
var newPath string
|
||||||
|
var realDst *string
|
||||||
|
|
||||||
|
if err = RealPath(path); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if dst == nil {
|
||||||
|
realDst = path
|
||||||
|
} else {
|
||||||
|
realDst = dst
|
||||||
|
}
|
||||||
|
|
||||||
|
newPath = filepath.Join(append([]string{*path}, subPaths...)...)
|
||||||
|
if err = RealPath(&newPath); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
*realDst = newPath
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
RealPathExists is like RealPath, but will also return a boolean as to whether the path
|
RealPathExists is like RealPath, but will also return a boolean as to whether the path
|
||||||
actually exists or not.
|
actually exists or not.
|
||||||
@ -437,10 +500,10 @@ func SearchFsPathsAsync(matcher FsSearchCriteriaAsync) {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
filterTimes checks a times.Timespec of a file using:
|
filterTimes checks a times.Timespec of a file using:
|
||||||
* an age specified by the caller
|
- an age specified by the caller
|
||||||
* an ageType bitmask for types of times to compare
|
- an ageType bitmask for types of times to compare
|
||||||
* an olderThan bool (if false, the file must be younger than)
|
- an olderThan bool (if false, the file must be younger than)
|
||||||
* an optional "now" timestamp for the age derivation.
|
- an optional "now" timestamp for the age derivation.
|
||||||
*/
|
*/
|
||||||
func filterTimes(tspec times.Timespec, age *time.Duration, ageType *pathTimeType, olderThan bool, now *time.Time) (include bool) {
|
func filterTimes(tspec times.Timespec, age *time.Duration, ageType *pathTimeType, olderThan bool, now *time.Time) (include bool) {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user