Merge pull request #118 from owncloud/fix-indexing-on-service-start
Fix indexing on service start
This commit is contained in:
@@ -6,4 +6,5 @@ This fixes a bug that accounts created through the web ui were not able to sign
|
||||
|
||||
https://github.com/owncloud/product/issues/224
|
||||
https://github.com/owncloud/ocis-accounts/pull/117
|
||||
https://github.com/owncloud/ocis-accounts/pull/118
|
||||
|
||||
|
||||
@@ -37,6 +37,28 @@ import (
|
||||
// accLock mutually exclude readers from writers on account files
|
||||
var accLock sync.Mutex
|
||||
|
||||
func (s Service) indexAccounts(path string) (err error) {
|
||||
var f *os.File
|
||||
if f, err = os.Open(path); err != nil {
|
||||
s.log.Error().Err(err).Str("dir", path).Msg("could not open accounts folder")
|
||||
return
|
||||
}
|
||||
list, err := f.Readdir(-1)
|
||||
f.Close()
|
||||
if err != nil {
|
||||
s.log.Error().Err(err).Str("dir", path).Msg("could not list accounts folder")
|
||||
return
|
||||
}
|
||||
for _, file := range list {
|
||||
err = s.indexAccount(file.Name())
|
||||
if err != nil {
|
||||
s.log.Error().Err(err).Str("file", file.Name()).Msg("could not index account")
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (s Service) indexAccount(id string) error {
|
||||
a := &proto.BleveAccount{
|
||||
BleveType: "account",
|
||||
|
||||
@@ -20,6 +20,28 @@ import (
|
||||
// accLock mutually exclude readers from writers on group files
|
||||
var groupLock sync.Mutex
|
||||
|
||||
func (s Service) indexGroups(path string) (err error) {
|
||||
var f *os.File
|
||||
if f, err = os.Open(path); err != nil {
|
||||
s.log.Error().Err(err).Str("dir", path).Msg("could not open groups folder")
|
||||
return
|
||||
}
|
||||
list, err := f.Readdir(-1)
|
||||
f.Close()
|
||||
if err != nil {
|
||||
s.log.Error().Err(err).Str("dir", path).Msg("could not list groups folder")
|
||||
return
|
||||
}
|
||||
for _, file := range list {
|
||||
err = s.indexGroup(file.Name())
|
||||
if err != nil {
|
||||
s.log.Error().Err(err).Str("file", file.Name()).Msg("could not index account")
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (s Service) indexGroup(id string) error {
|
||||
g := &proto.BleveGroup{
|
||||
BleveType: "group",
|
||||
|
||||
@@ -68,12 +68,18 @@ func New(opts ...Option) (s *Service, err error) {
|
||||
if err = s.createDefaultAccounts(accountsDir); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = s.indexAccounts(accountsDir); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// create default groups
|
||||
groupsDir := filepath.Join(cfg.Server.AccountsDataPath, "groups")
|
||||
if err = s.createDefaultGroups(groupsDir); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = s.indexGroups(groupsDir); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO watch folders for new records
|
||||
|
||||
@@ -293,11 +299,6 @@ func (s Service) createDefaultAccounts(accountsDir string) (err error) {
|
||||
s.log.Error().Err(err).Str("path", path).Interface("account", &accounts[i]).Msg("could not persist default account")
|
||||
return
|
||||
}
|
||||
if err = s.indexAccount(accounts[i].Id); err != nil {
|
||||
accounts[i].PasswordProfile.Password = "***REMOVED***"
|
||||
s.log.Error().Err(err).Str("path", path).Interface("account", &accounts[i]).Msg("could not index default account")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// set role for admin users and regular users
|
||||
@@ -376,10 +377,6 @@ func (s Service) createDefaultGroups(groupsDir string) (err error) {
|
||||
s.log.Error().Err(err).Str("path", path).Interface("group", &groups[i]).Msg("could not persist default group")
|
||||
return
|
||||
}
|
||||
if err = s.indexGroup(groups[i].Id); err != nil {
|
||||
s.log.Error().Err(err).Str("path", path).Interface("group", &groups[i]).Msg("could not index default group")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if !fi.IsDir() {
|
||||
|
||||
Reference in New Issue
Block a user