Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
search: fix search behavior, return match list
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuAlfageme committed Feb 8, 2023
1 parent d1f2530 commit 73a716d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
15 changes: 2 additions & 13 deletions pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,19 +735,8 @@ func (c *Client) SearchDir(ctx context.Context, auth eosclient.Authorization, se
return nil, errors.Errorf("eosclient: ilegal search string: %s", searchString)
}
// TODO: set a timeout for the find in case it goes out of hand
stdout, stderr, err := c.executeEOS(ctx, args, auth)
if err != nil {
// Errcode 7: "TOOBIG"
if stdout != "" {
log.Debug().Msgf("eos find stdout= %s", stdout)
log.Debug().Msgf("=========== eos find stderr =========== %s", stderr)
return c.parseFind(ctx, auth, path, stdout)
} else {
log.Debug().Msgf("eosbinary - user had insufficient permissions to search part of the directory")
// There will be errors; we cannot ignore them:
return nil, errors.Wrapf(err, "eosclient: error listing fn=%s", path)
}
}
stdout, _, _ := c.executeEOS(ctx, args, auth)
// We can ignore errors and stderr, we're just interested on the EOS output
log.Debug().Msgf("eos find stdout= %s", stdout)
return c.parseFind(ctx, auth, path, stdout)
}
Expand Down
26 changes: 18 additions & 8 deletions pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1336,25 +1336,29 @@ func (fs *eosfs) ListFolder(ctx context.Context, ref *provider.Reference, mdKeys
// - also check that searchString not empty:
searchString = mdKeys[i+1]

if searchString == "" {
return nil, errtypes.NotSupported("Search requires a search string")
}

log.Debug().Msgf("eosfs: running search: path=%s searchString=%s", p, searchString)

eosFileInfos, err := fs.c.SearchDir(ctx, auth, searchString, p)

if err != nil {
return nil, errors.Wrap(err, "eosfs: error searching")
}

for _, eosFileInfo := range eosFileInfos {
// filter out sys files
if !fs.conf.ShowHiddenSysFiles {
base := path.Base(eosFileInfo.File)
if hiddenReg.MatchString(base) {
continue
}
}

if finfo, err := fs.convertToFileReference(ctx, eosFileInfo); err == nil {
log.Debug().Msgf("seach: eosFileInfo %s", eosFileInfo.File)

// Search all files, hidden and not, for the time being

if finfo, err := fs.convertToResourceInfo(ctx, eosFileInfo); err == nil {
log.Debug().Msgf("eosfs: file name from search %s", finfo.Name)
finfos = append(finfos, finfo)
} else {
log.Error().Err(err).Msg(" wtf 🥘")
}
}

Expand Down Expand Up @@ -2120,6 +2124,8 @@ func (fs *eosfs) convertToResourceInfo(ctx context.Context, eosFileInfo *eosclie
}

func (fs *eosfs) convertToFileReference(ctx context.Context, eosFileInfo *eosclient.FileInfo) (*provider.ResourceInfo, error) {
log := appctx.GetLogger(ctx)
log.Debug().Msg("convertToFileReference")
info, err := fs.convert(ctx, eosFileInfo)
if err != nil {
return nil, err
Expand Down Expand Up @@ -2258,6 +2264,8 @@ func mergePermissions(l *provider.ResourcePermissions, r *provider.ResourcePermi
}

func (fs *eosfs) convert(ctx context.Context, eosFileInfo *eosclient.FileInfo) (*provider.ResourceInfo, error) {
log := appctx.GetLogger(ctx)
log.Debug().Msg("convert")
path, err := fs.unwrap(ctx, eosFileInfo.File)
if err != nil {
return nil, err
Expand Down Expand Up @@ -2293,6 +2301,8 @@ func (fs *eosfs) convert(ctx context.Context, eosFileInfo *eosclient.FileInfo) (
}
}

log.Debug().Msgf("convert: marshalling the eosFileInfo %s", eosFileInfo)

info := &provider.ResourceInfo{
Id: &provider.ResourceId{OpaqueId: fmt.Sprintf("%d", eosFileInfo.Inode)},
Path: path,
Expand Down

0 comments on commit 73a716d

Please sign in to comment.