1
0
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:
David Forsythe 2011-03-29 14:23:36 -04:00 committed by Russ Cox
parent 04b7da80cc
commit 85c79ef7cb
4 changed files with 21 additions and 21 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}