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

Commit

Permalink
eosbinary: change name parameter and sandbox project
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuAlfageme committed Jan 23, 2023
1 parent 799351d commit 9f1ba44
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 34 deletions.
176 changes: 146 additions & 30 deletions internal/http/services/owncloud/ocdav/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *svc) doSearchFiles(w http.ResponseWriter, r *http.Request, sf *reportSe
}

// TODO(salfagem): hardcoded path for the time being:
ref := &provider.Reference{Path: "/eos/project/c/cernbox"}
ref := &provider.Reference{Path: "/eos/project/t/test"}

req := &provider.ListContainerRequest{Opaque: &typespb.Opaque{
Map: opaqueMap,
Expand All @@ -103,52 +103,168 @@ func (s *svc) doSearchFiles(w http.ResponseWriter, r *http.Request, sf *reportSe
return
}

log.Debug().Msgf("search: found %d matches", len(res.Infos))

for _, v := range res.Infos {
log.Debug().Msg(v.Path)
}

data := `
<?xml version="1.0" encoding="UTF-8"?>
<d:multistatus xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:s="http://sabredav.org/ns">
<d:response>
<d:href>/remote.php/dav/spaces/1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51/asd.txt</d:href>
<d:response>
<d:href>/remote.php/dav/files/cboxbot/eos/project/a/awesomeproject/New%20Text%20Document.txt</d:href>
<d:propstat>
<d:prop>
<oc:fileid>newproject-a!420307062</oc:fileid>
<oc:file-parent>newproject-a!616510</oc:file-parent>
<oc:name>New Text Document.txt</oc:name>
<d:getlastmodified>2022-12-05T16:12:20Z</d:getlastmodified>
<d:getcontenttype>text/plain</d:getcontenttype>
<oc:permissions>SRDNVCKZ</oc:permissions>
<d:getetag />
<d:resourcetype>
<d:collection />
</d:resourcetype>
<oc:size>0</oc:size>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
<d:response>
<d:href>/remote.php/dav/files/cboxbot/eos/project/a/awesomeproject/New%20text%20file.txt</d:href>
<d:propstat>
<d:prop>
<oc:fileid>1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51!d5613880-307c-4e3e-b56d-97839fcf6d03</oc:fileid>
<oc:file-parent>1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51!4c510ada-c86b-4815-8820-42cdf82c3d51</oc:file-parent>
<oc:name>asd.txt</oc:name>
<d:getlastmodified>2022-11-08T10:45:16Z</d:getlastmodified>
<d:prop>
<oc:fileid>newproject-a!166399624</oc:fileid>
<oc:file-parent>newproject-a!616510</oc:file-parent>
<oc:name>New text file.txt</oc:name>
<d:getlastmodified>2022-12-05T16:12:20Z</d:getlastmodified>
<d:getcontenttype>text/plain</d:getcontenttype>
<oc:permissions>RDNVW</oc:permissions>
<oc:permissions>SRDNVCKZ</oc:permissions>
<d:getetag />
<d:resourcetype />
<d:getcontentlength>0</d:getcontentlength>
<oc:score>0.4809828996658325</oc:score>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
<d:resourcetype>
<d:collection />
</d:resourcetype>
<oc:size>5</oc:size>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
<d:response>
<d:href>/remote.php/dav/spaces/1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51/asdddddd</d:href>
</d:response>
<d:response>
<d:href>/remote.php/dav/files/cboxbot/eos/project/a/awesomeproject/recover.txt</d:href>
<d:propstat>
<d:prop>
<oc:fileid>1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51!fa3c7a85-5fc4-46d3-a0b1-293a282da1b7</oc:fileid>
<oc:file-parent>1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51!4c510ada-c86b-4815-8820-42cdf82c3d51</oc:file-parent>
<oc:name>asdddddd</oc:name>
<d:getlastmodified>2022-11-08T10:45:32Z</d:getlastmodified>
<d:getcontenttype>httpd/unix-directory</d:getcontenttype>
<oc:permissions>RDNVCK</oc:permissions>
<d:prop>
<oc:fileid>newproject-a!493427700</oc:fileid>
<oc:file-parent>newproject-a!616510</oc:file-parent>
<oc:name>recover.txt</oc:name>
<d:getlastmodified>2022-12-05T16:12:20Z</d:getlastmodified>
<d:getcontenttype>text/plain</d:getcontenttype>
<oc:permissions>SRDNVCKZ</oc:permissions>
<d:getetag />
<d:resourcetype>
<d:collection />
<d:collection />
</d:resourcetype>
<oc:size>0</oc:size>
<oc:score>0.4809828996658325</oc:score>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
<d:response>
<d:href>/remote.php/dav/files/cboxbot/eos/project/a/awesomeproject/test_support.txt</d:href>
<d:propstat>
<d:prop>
<oc:fileid>newproject-a!420300390</oc:fileid>
<oc:file-parent>newproject-a!616510</oc:file-parent>
<oc:name>test_support.txt</oc:name>
<d:getlastmodified>2022-12-05T16:12:20Z</d:getlastmodified>
<d:getcontenttype>text/plain</d:getcontenttype>
<oc:permissions>SRDNVCKZ</oc:permissions>
<d:getetag />
<d:resourcetype>
<d:collection />
</d:resourcetype>
<oc:size>0</oc:size>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
<d:response>
<d:href>/remote.php/dav/files/cboxbot/eos/project/a/awesomeproject/testing.txt</d:href>
<d:propstat>
<d:prop>
<oc:fileid>newproject-a!420300167</oc:fileid>
<oc:file-parent>newproject-a!616510</oc:file-parent>
<oc:name>testing.txt</oc:name>
<d:getlastmodified>2022-12-05T16:12:20Z</d:getlastmodified>
<d:getcontenttype>text/plain</d:getcontenttype>
<oc:permissions>SRDNVCKZ</oc:permissions>
<d:getetag />
<d:resourcetype>
<d:collection />
</d:resourcetype>
<oc:size>0</oc:size>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
<d:response>
<d:href>/remote.php/dav/files/cboxbot/eos/project/a/awesomeproject/testing2.txt</d:href>
<d:propstat>
<d:prop>
<oc:fileid>newproject-a!420300326</oc:fileid>
<oc:file-parent>newproject-a!616510</oc:file-parent>
<oc:name>testing2.txt</oc:name>
<d:getlastmodified>2022-12-05T16:12:20Z</d:getlastmodified>
<d:getcontenttype>text/plain</d:getcontenttype>
<oc:permissions>SRDNVCKZ</oc:permissions>
<d:getetag />
<d:resourcetype>
<d:collection />
</d:resourcetype>
<oc:size>0</oc:size>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
<d:response>
<d:href>/remote.php/dav/files/cboxbot/eos/project/a/awesomeproject/Denied%20Folder/New%20file.txt</d:href>
<d:propstat>
<d:prop>
<oc:fileid>newproject-a!437033942</oc:fileid>
<oc:file-parent>newproject-a!67942728</oc:file-parent>
<oc:name>New file.txt</oc:name>
<d:getlastmodified>2022-12-05T16:12:20Z</d:getlastmodified>
<d:getcontenttype>text/plain</d:getcontenttype>
<oc:permissions>SRDNVCKZ</oc:permissions>
<d:getetag />
<d:resourcetype>
<d:collection />
</d:resourcetype>
<oc:size>0</oc:size>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
<d:response>
<d:href>/remote.php/dav/files/cboxbot/eos/project/a/awesomeproject/test_versions/test.txt</d:href>
<d:propstat>
<d:prop>
<oc:fileid>newproject-a!506354963</oc:fileid>
<oc:file-parent>newproject-a!73758625</oc:file-parent>
<oc:name>test.txt</oc:name>
<d:getlastmodified>2022-12-05T16:12:20Z</d:getlastmodified>
<d:getcontenttype>text/plain</d:getcontenttype>
<oc:permissions>SRDNVCKZ</oc:permissions>
<d:getetag />
<d:resourcetype>
<d:collection />
</d:resourcetype>
<oc:size>9</oc:size>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
</d:multistatus>
</d:response>
</d:multistatus>
`
w.Write([]byte(data))
w.WriteHeader(207)
Expand Down
9 changes: 6 additions & 3 deletions pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,11 +720,11 @@ func (c *Client) List(ctx context.Context, auth eosclient.Authorization, path st
// List the contents of the directory given by path with depth infinity
func (c *Client) SearchDir(ctx context.Context, auth eosclient.Authorization, searchString string, path string) ([]*eosclient.FileInfo, error) {
// TODO(salfagem): path is truncated - i.e. /c/cernbox (not absolute)
args := []string{"newfind", "--fileinfo", "-name", searchString, path}
args := []string{"newfind", "--fileinfo", "--name", searchString, path}
log := appctx.GetLogger(ctx)
log.Debug().Msgf("eosbinary search with args: %s", args)
// Safeguard #2 to prevent the search to go to undesired places:
if !strings.HasPrefix(path, "/eos/project/c/cernbox") {
if !strings.HasPrefix(path, "/eos/project/t/test") {
log.Debug().Msgf("eosbinary - prefix doesn't match")
return nil, errors.Errorf("eosclient: search path out of bounds fn=%s", path)
}
Expand All @@ -741,9 +741,12 @@ func (c *Client) SearchDir(ctx context.Context, auth eosclient.Authorization, se
case errtypes.NotFound, errtypes.PermissionDenied:
log.Debug().Msgf("eosbinary - user had insufficient permissions to search part of the directory")
default:
return nil, errors.Wrapf(err, "eosclient: error listing fn=%s", path)
log.Error().Msgf("ERRROR LISTING= %s", stdout)
// There will be errors:
//return nil, errors.Wrapf(err, "eosclient: error listing fn=%s", path)
}
}
log.Debug().Msgf("eos find stdout= %s", stdout)
return c.parseFind(ctx, auth, path, stdout)
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ func (fs *eosfs) ListFolder(ctx context.Context, ref *provider.Reference, mdKeys
// - also check that searchString not empty:
searchString = mdKeys[i+1]

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

eosFileInfos, err := fs.c.SearchDir(ctx, auth, searchString, p)
if err != nil {
Expand All @@ -1353,6 +1353,7 @@ func (fs *eosfs) ListFolder(ctx context.Context, ref *provider.Reference, mdKeys
}

if finfo, err := fs.convertToFileReference(ctx, eosFileInfo); err == nil {
log.Debug().Msgf("eosfs: file name from search %s", finfo.Name)
finfos = append(finfos, finfo)
}
}
Expand Down

0 comments on commit 9f1ba44

Please sign in to comment.