Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use a relative reference for the stat request in the cs3 api #74

Merged
merged 1 commit into from
May 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions src/core/cs3iface.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,15 @@ def getuseridfromcreds(token, _wopiuser):
def _getcs3reference(endpoint, fileref):
'''Generates a CS3 reference for a given fileref, covering the following cases:
absolute path, relative hybrid path, fully opaque fileid'''
if fileref[0] == '/':
# assume this is a filepath
ref = cs3spr.Reference(path=fileref)
elif fileref.find('/') > 0:
if fileref.find('/') > 0:
# assume we have a relative path in the form `<parent_opaque_id>/<base_filename>`,
# also works if we get `<parent_opaque_id>/<path>/<filename>`
ref = cs3spr.Reference(resource_id=cs3spr.ResourceId(storage_id=endpoint,
opaque_id=fileref[:fileref.find('/')]),
path='.' + fileref[fileref.find('/'):])
else:
# assume we have an opaque fileid
ref = cs3spr.Reference(resource_id=cs3spr.ResourceId(storage_id=endpoint, opaque_id=fileref))
ref = cs3spr.Reference(resource_id=cs3spr.ResourceId(storage_id=endpoint, opaque_id=fileref), path='.')
return ref


Expand All @@ -80,8 +77,8 @@ def authenticate_for_test(userid, userpwd):

def stat(endpoint, fileref, userid, versioninv=1):
'''Stat a file and returns (size, mtime) as well as other extended info using the given userid as access token.
Note that endpoint here means the storage id, and fileref can be either a path (which MUST begin with /),
or an id (which MUST NOT start with a /). The versioninv flag is natively supported by Reva.'''
Note that endpoint here means the storage id, and fileref can be either a path in the form (parent_id/base_filename)
or a pure id (cf. _getcs3reference). The versioninv flag is natively supported by Reva.'''
tstart = time.time()
ref = _getcs3reference(endpoint, fileref)
statInfo = ctx['cs3gw'].Stat(request=cs3sp.StatRequest(ref=ref), metadata=[('x-access-token', userid)])
Expand All @@ -100,12 +97,9 @@ def stat(endpoint, fileref, userid, versioninv=1):
raise IOError('Unexpected type %d' % statInfo.info.type)

inode = common.encodeinode(statInfo.info.id.storage_id, statInfo.info.id.opaque_id)
# in case we got a relative path, build an hybrid path that can be used to reference the file:
# note that as per specs the parent_id MUST be available in this case
if statInfo.info.path[0] == '/':
filepath = statInfo.info.path
else:
filepath = statInfo.info.parent_id.opaque_id + '/' + os.path.basename(statInfo.info.path)
# here we build an hybrid path that can be used to reference the file, as the path is actually just the basename
# (and eventually the CS3 APIs should be updated to reflect that): note that as per specs the parent_id MUST be available
filepath = statInfo.info.parent_id.opaque_id + '/' + os.path.basename(statInfo.info.path)
log.info('msg="Invoked stat" fileref="%s" trace="%s" inode="%s" filepath="%s" elapsedTimems="%.1f"' %
(fileref, statInfo.status.trace, inode, filepath, (tend-tstart)*1000))
return {
Expand Down