1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-25 18:15:57 +01:00

Check all group files on startup, not just the toplevel directory.

This commit is contained in:
Juliusz Chroboczek 2021-01-13 22:56:43 +01:00
parent 82827453f0
commit 61990ff1ef

View file

@ -821,32 +821,41 @@ func GetPublic() []Public {
} }
func ReadPublicGroups() { func ReadPublicGroups() {
dir, err := os.Open(Directory) err := filepath.Walk(
if err != nil { Directory,
return func(path string, fi os.FileInfo, err error) error {
} if err != nil {
defer dir.Close() log.Printf("Group file %v: %v", path, err)
fis, err := dir.Readdir(-1)
if err != nil {
log.Printf("readPublicGroups: %v", err)
return
}
for _, fi := range fis {
if !strings.HasSuffix(fi.Name(), ".json") {
continue
}
name := fi.Name()[:len(fi.Name())-5]
desc, err := GetDescription(name)
if err != nil {
if !os.IsNotExist(err) {
log.Printf("Reading group %v: %v", name, err)
} }
continue if fi.IsDir() {
} return nil
if desc.Public { }
Add(name, desc) filename, err := filepath.Rel(Directory, path)
} if err != nil {
log.Printf("Group file %v: %v", path, err)
return nil
}
if !strings.HasSuffix(filename, ".json") {
log.Printf(
"Unexpected extension for group file %v",
path,
)
return nil
}
name := filename[:len(filename)-5]
desc, err := GetDescription(name)
if err != nil {
log.Printf("Group file %v: %v", path, err)
return nil
}
if desc.Public {
Add(name, desc)
}
return nil
},
)
if err != nil {
log.Printf("Couldn't read groups: %v", err);
} }
} }