mirror of
https://github.com/golang/go
synced 2024-11-12 08:10:21 -07:00
os: fix FileInfo.Name returned by Stat
Fixes #1645. R=rsc CC=golang-dev https://golang.org/cl/4321045
This commit is contained in:
parent
04b7da80cc
commit
85c79ef7cb
@ -102,3 +102,21 @@ func Truncate(name string, size int64) Error {
|
||||
}
|
||||
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
|
||||
fi.Atime_ns = syscall.TimespecToNsec(stat.Atimespec)
|
||||
fi.Mtime_ns = syscall.TimespecToNsec(stat.Mtimespec)
|
||||
fi.Ctime_ns = syscall.TimespecToNsec(stat.Ctimespec)
|
||||
for i := len(name) - 1; i >= 0; i-- {
|
||||
if name[i] == '/' {
|
||||
name = name[i+1:]
|
||||
break
|
||||
}
|
||||
}
|
||||
fi.Name = name
|
||||
fi.Name = basename(name)
|
||||
if isSymlink(lstat) && !isSymlink(stat) {
|
||||
fi.FollowedSymlink = true
|
||||
}
|
||||
|
@ -24,13 +24,7 @@ func fileInfoFromStat(name string, fi *FileInfo, lstat, stat *syscall.Stat_t) *F
|
||||
fi.Atime_ns = syscall.TimespecToNsec(stat.Atimespec)
|
||||
fi.Mtime_ns = syscall.TimespecToNsec(stat.Mtimespec)
|
||||
fi.Ctime_ns = syscall.TimespecToNsec(stat.Ctimespec)
|
||||
for i := len(name) - 1; i >= 0; i-- {
|
||||
if name[i] == '/' {
|
||||
name = name[i+1:]
|
||||
break
|
||||
}
|
||||
}
|
||||
fi.Name = name
|
||||
fi.Name = basename(name)
|
||||
if isSymlink(lstat) && !isSymlink(stat) {
|
||||
fi.FollowedSymlink = true
|
||||
}
|
||||
|
@ -24,13 +24,7 @@ func fileInfoFromStat(name string, fi *FileInfo, lstat, stat *syscall.Stat_t) *F
|
||||
fi.Atime_ns = syscall.TimespecToNsec(stat.Atim)
|
||||
fi.Mtime_ns = syscall.TimespecToNsec(stat.Mtim)
|
||||
fi.Ctime_ns = syscall.TimespecToNsec(stat.Ctim)
|
||||
for i := len(name) - 1; i >= 0; i-- {
|
||||
if name[i] == '/' {
|
||||
name = name[i+1:]
|
||||
break
|
||||
}
|
||||
}
|
||||
fi.Name = name
|
||||
fi.Name = basename(name)
|
||||
if isSymlink(lstat) && !isSymlink(stat) {
|
||||
fi.FollowedSymlink = true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user