Commit 85c79ef7 authored by David Forsythe's avatar David Forsythe Committed by Russ Cox

os: fix FileInfo.Name returned by Stat

Fixes #1645.

R=rsc
CC=golang-dev
https://golang.org/cl/4321045
parent 04b7da80
...@@ -102,3 +102,21 @@ func Truncate(name string, size int64) Error { ...@@ -102,3 +102,21 @@ func Truncate(name string, size int64) Error {
} }
return nil return nil
} }
// basename removes trailing slashes and the leading directory name from path name
func basename(name string) string {
i := len(name) - 1
// Remove trailing slashes
for ; i > 0 && name[i] == '/'; i-- {
name = name[:i]
}
// Remove leading directory name
for i--; i >= 0; i-- {
if name[i] == '/' {
name = name[i+1:]
break
}
}
return name
}
...@@ -24,13 +24,7 @@ func fileInfoFromStat(name string, fi *FileInfo, lstat, stat *syscall.Stat_t) *F ...@@ -24,13 +24,7 @@ func fileInfoFromStat(name string, fi *FileInfo, lstat, stat *syscall.Stat_t) *F
fi.Atime_ns = syscall.TimespecToNsec(stat.Atimespec) fi.Atime_ns = syscall.TimespecToNsec(stat.Atimespec)
fi.Mtime_ns = syscall.TimespecToNsec(stat.Mtimespec) fi.Mtime_ns = syscall.TimespecToNsec(stat.Mtimespec)
fi.Ctime_ns = syscall.TimespecToNsec(stat.Ctimespec) fi.Ctime_ns = syscall.TimespecToNsec(stat.Ctimespec)
for i := len(name) - 1; i >= 0; i-- { fi.Name = basename(name)
if name[i] == '/' {
name = name[i+1:]
break
}
}
fi.Name = name
if isSymlink(lstat) && !isSymlink(stat) { if isSymlink(lstat) && !isSymlink(stat) {
fi.FollowedSymlink = true fi.FollowedSymlink = true
} }
......
...@@ -24,13 +24,7 @@ func fileInfoFromStat(name string, fi *FileInfo, lstat, stat *syscall.Stat_t) *F ...@@ -24,13 +24,7 @@ func fileInfoFromStat(name string, fi *FileInfo, lstat, stat *syscall.Stat_t) *F
fi.Atime_ns = syscall.TimespecToNsec(stat.Atimespec) fi.Atime_ns = syscall.TimespecToNsec(stat.Atimespec)
fi.Mtime_ns = syscall.TimespecToNsec(stat.Mtimespec) fi.Mtime_ns = syscall.TimespecToNsec(stat.Mtimespec)
fi.Ctime_ns = syscall.TimespecToNsec(stat.Ctimespec) fi.Ctime_ns = syscall.TimespecToNsec(stat.Ctimespec)
for i := len(name) - 1; i >= 0; i-- { fi.Name = basename(name)
if name[i] == '/' {
name = name[i+1:]
break
}
}
fi.Name = name
if isSymlink(lstat) && !isSymlink(stat) { if isSymlink(lstat) && !isSymlink(stat) {
fi.FollowedSymlink = true fi.FollowedSymlink = true
} }
......
...@@ -24,13 +24,7 @@ func fileInfoFromStat(name string, fi *FileInfo, lstat, stat *syscall.Stat_t) *F ...@@ -24,13 +24,7 @@ func fileInfoFromStat(name string, fi *FileInfo, lstat, stat *syscall.Stat_t) *F
fi.Atime_ns = syscall.TimespecToNsec(stat.Atim) fi.Atime_ns = syscall.TimespecToNsec(stat.Atim)
fi.Mtime_ns = syscall.TimespecToNsec(stat.Mtim) fi.Mtime_ns = syscall.TimespecToNsec(stat.Mtim)
fi.Ctime_ns = syscall.TimespecToNsec(stat.Ctim) fi.Ctime_ns = syscall.TimespecToNsec(stat.Ctim)
for i := len(name) - 1; i >= 0; i-- { fi.Name = basename(name)
if name[i] == '/' {
name = name[i+1:]
break
}
}
fi.Name = name
if isSymlink(lstat) && !isSymlink(stat) { if isSymlink(lstat) && !isSymlink(stat) {
fi.FollowedSymlink = true fi.FollowedSymlink = true
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment