Skip to content

Commit c1bed07

Browse files
committed
Issue #276.
1 parent a0771f2 commit c1bed07

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

tests/conn_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,17 @@ func TestConn_Filename(t *testing.T) {
295295
t.Parallel()
296296

297297
file := filepath.Join(t.TempDir(), "test.db")
298+
f, err := os.Create(file)
299+
if err != nil {
300+
t.Fatal(err)
301+
}
302+
f.Close()
303+
304+
file, err = filepath.EvalSymlinks(file)
305+
if err != nil {
306+
t.Fatal(err)
307+
}
308+
298309
db, err := sqlite3.Open(file)
299310
if err != nil {
300311
t.Fatal(err)

vfs/file.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,28 @@ import (
1313
type vfsOS struct{}
1414

1515
func (vfsOS) FullPathname(path string) (string, error) {
16-
path, err := filepath.Abs(path)
16+
link, err := evalSymlinks(path)
1717
if err != nil {
1818
return "", err
1919
}
20-
return path, testSymlinks(filepath.Dir(path))
20+
full, err := filepath.Abs(link)
21+
if err == nil && link != path {
22+
err = _OK_SYMLINK
23+
}
24+
return full, err
2125
}
2226

23-
func testSymlinks(path string) error {
24-
p, err := filepath.EvalSymlinks(path)
25-
if err != nil {
26-
return err
27+
func evalSymlinks(path string) (string, error) {
28+
var file string
29+
_, err := os.Lstat(path)
30+
if errors.Is(err, fs.ErrNotExist) {
31+
path, file = filepath.Split(path)
2732
}
28-
if p != path {
29-
return _OK_SYMLINK
33+
path, err = filepath.EvalSymlinks(path)
34+
if err != nil {
35+
return "", err
3036
}
31-
return nil
37+
return filepath.Join(path, file), nil
3238
}
3339

3440
func (vfsOS) Delete(path string, syncDir bool) error {

0 commit comments

Comments
 (0)