mirror of
https://github.com/golang/go
synced 2024-11-26 09:08:07 -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.
|
if dirent.Ino == 0 { // File absent in directory.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
var name = string(dirent.Name[0:dirent.Namlen]);
|
||||||
|
if name == "." || name == ".." { // Useless names
|
||||||
|
continue
|
||||||
|
}
|
||||||
count--;
|
count--;
|
||||||
if len(names) == cap(names) {
|
if len(names) == cap(names) {
|
||||||
nnames := make([]string, len(names), 2*len(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 = nnames;
|
||||||
}
|
}
|
||||||
names = names[0:len(names)+1];
|
names = names[0:len(names)+1];
|
||||||
names[len(names)-1] = string(dirent.Name[0:dirent.Namlen]);
|
names[len(names)-1] = name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return names, nil
|
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.
|
if dirent.Ino == 0 { // File absent in directory.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
var name = string(dirent.Name[0:clen(dirent.Namlen)]);
|
||||||
|
if name == "." || name == ".." { // Useless names
|
||||||
|
continue
|
||||||
|
}
|
||||||
count--;
|
count--;
|
||||||
if len(names) == cap(names) {
|
if len(names) == cap(names) {
|
||||||
nnames := make([]string, len(names), 2*len(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 = nnames;
|
||||||
}
|
}
|
||||||
names = names[0:len(names)+1];
|
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;
|
return names, nil;
|
||||||
|
@ -110,6 +110,9 @@ func testReaddirnames(dir string, contents []string, t *testing.T) {
|
|||||||
for i, m := range contents {
|
for i, m := range contents {
|
||||||
found := false;
|
found := false;
|
||||||
for j, n := range s {
|
for j, n := range s {
|
||||||
|
if n == "." || n == ".." {
|
||||||
|
t.Errorf("got %s in directory", n);
|
||||||
|
}
|
||||||
if m == n {
|
if m == n {
|
||||||
if found {
|
if found {
|
||||||
t.Error("present twice:", m);
|
t.Error("present twice:", m);
|
||||||
|
Loading…
Reference in New Issue
Block a user