mirror of https://github.com/spf13/afero.git
allow absolute paths in BasePathFs when prefix is "" on windows
This commit is contained in:
parent
5c4385aa20
commit
08d1d4a126
|
@ -51,7 +51,7 @@ func NewBasePathFs(source Fs, path string) Fs {
|
|||
// on a file outside the base path it returns the given file name and an error,
|
||||
// else the given file with the base path prepended
|
||||
func (b *BasePathFs) RealPath(name string) (path string, err error) {
|
||||
if err := validateBasePathName(name); err != nil {
|
||||
if err := validateBasePathName(name, b.path); err != nil {
|
||||
return name, err
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ func (b *BasePathFs) RealPath(name string) (path string, err error) {
|
|||
return path, nil
|
||||
}
|
||||
|
||||
func validateBasePathName(name string) error {
|
||||
func validateBasePathName(name string, base string) error {
|
||||
if runtime.GOOS != "windows" {
|
||||
// Not much to do here;
|
||||
// the virtual file paths all look absolute on *nix.
|
||||
|
@ -73,7 +73,7 @@ func validateBasePathName(name string) error {
|
|||
|
||||
// On Windows a common mistake would be to provide an absolute OS path
|
||||
// We could strip out the base part, but that would not be very portable.
|
||||
if filepath.IsAbs(name) {
|
||||
if filepath.IsAbs(name) && base != "" {
|
||||
return os.ErrNotExist
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue