mirror of https://github.com/spf13/afero.git
os symlink use rel path
This commit is contained in:
parent
e2113964d5
commit
a269d78f6d
7
os.go
7
os.go
|
@ -16,6 +16,7 @@ package afero
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -105,7 +106,11 @@ func (OsFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (OsFs) SymlinkIfPossible(oldname, newname string) error {
|
func (OsFs) SymlinkIfPossible(oldname, newname string) error {
|
||||||
return os.Symlink(oldname, newname)
|
relpath, err := filepath.Rel(filepath.Dir(newname), oldname)
|
||||||
|
if err != nil {
|
||||||
|
return &os.LinkError{Op: "symlink", Old: oldname, New: newname, Err: err}
|
||||||
|
}
|
||||||
|
return os.Symlink(relpath, newname)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (OsFs) ReadlinkIfPossible(name string) (string, error) {
|
func (OsFs) ReadlinkIfPossible(name string) (string, error) {
|
||||||
|
|
|
@ -132,7 +132,7 @@ func TestReadlinkIfPossible(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
testRead := func(r LinkReader, name string, output *string) {
|
testRead := func(r LinkReader, name string, output *string) {
|
||||||
_, err := r.ReadlinkIfPossible(name)
|
str, err := r.ReadlinkIfPossible(name)
|
||||||
if (err != nil) && (output == nil) {
|
if (err != nil) && (output == nil) {
|
||||||
t.Fatalf("Error reading link, expected success, got error: %v", err)
|
t.Fatalf("Error reading link, expected success, got error: %v", err)
|
||||||
} else if (err == nil) && (output != nil) {
|
} else if (err == nil) && (output != nil) {
|
||||||
|
@ -140,6 +140,7 @@ func TestReadlinkIfPossible(t *testing.T) {
|
||||||
} else if err != nil && err.Error() != *output && !strings.HasSuffix(err.Error(), *output) {
|
} else if err != nil && err.Error() != *output && !strings.HasSuffix(err.Error(), *output) {
|
||||||
t.Fatalf("Error reading link, expected error '%v', instead received '%v'", *output, err)
|
t.Fatalf("Error reading link, expected error '%v', instead received '%v'", *output, err)
|
||||||
}
|
}
|
||||||
|
t.Logf("str: %v", str)
|
||||||
}
|
}
|
||||||
|
|
||||||
notSupported := ErrNoReadlink.Error()
|
notSupported := ErrNoReadlink.Error()
|
||||||
|
|
Loading…
Reference in New Issue