mirror of
https://github.com/golang/go
synced 2024-11-26 08:48:13 -07:00
throw away . and .. in directory listings
R=r DELTA=13 (11 added, 0 deleted, 2 changed) OCL=27147 CL=27154
This commit is contained in:
parent
61ba160120
commit
f13ce3ab34
@ -50,6 +50,10 @@ func readdirnames(file *File, count int) (names []string, err *os.Error) {
|
||||
if dirent.Ino == 0 { // File absent in directory.
|
||||
continue
|
||||
}
|
||||
var name = string(dirent.Name[0:dirent.Namlen]);
|
||||
if name == "." || name == ".." { // Useless names
|
||||
continue
|
||||
}
|
||||
count--;
|
||||
if len(names) == cap(names) {
|
||||
nnames := make([]string, len(names), 2*len(names));
|
||||
@ -59,7 +63,7 @@ func readdirnames(file *File, count int) (names []string, err *os.Error) {
|
||||
names = nnames;
|
||||
}
|
||||
names = names[0:len(names)+1];
|
||||
names[len(names)-1] = string(dirent.Name[0:dirent.Namlen]);
|
||||
names[len(names)-1] = name;
|
||||
}
|
||||
}
|
||||
return names, nil
|
||||
|
@ -59,6 +59,10 @@ func readdirnames(file *File, count int) (names []string, err *os.Error) {
|
||||
if dirent.Ino == 0 { // File absent in directory.
|
||||
continue
|
||||
}
|
||||
var name = string(dirent.Name[0:clen(dirent.Namlen)]);
|
||||
if name == "." || name == ".." { // Useless names
|
||||
continue
|
||||
}
|
||||
count--;
|
||||
if len(names) == cap(names) {
|
||||
nnames := make([]string, len(names), 2*len(names));
|
||||
@ -68,7 +72,7 @@ func readdirnames(file *File, count int) (names []string, err *os.Error) {
|
||||
names = nnames;
|
||||
}
|
||||
names = names[0:len(names)+1];
|
||||
names[len(names)-1] = string(dirent.Name[0:clen(dirent.Name)]);
|
||||
names[len(names)-1] = name;
|
||||
}
|
||||
}
|
||||
return names, nil;
|
||||
|
@ -110,6 +110,9 @@ func testReaddirnames(dir string, contents []string, t *testing.T) {
|
||||
for i, m := range contents {
|
||||
found := false;
|
||||
for j, n := range s {
|
||||
if n == "." || n == ".." {
|
||||
t.Errorf("got %s in directory", n);
|
||||
}
|
||||
if m == n {
|
||||
if found {
|
||||
t.Error("present twice:", m);
|
||||
|
Loading…
Reference in New Issue
Block a user