Skip to content

Commit

Permalink
support cs3api for REVA edge
Browse files Browse the repository at this point in the history
Co-authored-by: Giuseppe Lo Presti <[email protected]>
Co-authored-by: Willy Kloucek <[email protected]>
  • Loading branch information
wkloucek and glpatcern committed May 6, 2022
1 parent 6baa04c commit a35d804
Showing 1 changed file with 7 additions and 13 deletions.
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

0 comments on commit a35d804

Please sign in to comment.