Skip to content

Commit

Permalink
Fixed xrootd xattr methods
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Nov 26, 2021
1 parent 114beb9 commit 16ff754
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/core/wopiutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def storeWopiLock(fileid, operation, lock, oldlock, acctok, isoffice):
# else it's our lock, refresh it and return
st.refreshlock(acctok['endpoint'], acctok['filename'], acctok['userid'], \
jwt.encode(lockcontent, srv.wopisecret, algorithm='HS256'))
log.info('msg="%s" filename="%s" token="%s" lock="%s" result="success"' %
log.info('msg="%s" filename="%s" token="%s" lock="%s" result="refreshed"' %
(operation.title(), acctok['filename'], flask.request.args['access_token'][-20:], lock))
return 'OK', http.client.OK
# any other error is logged and raised
Expand Down Expand Up @@ -359,9 +359,9 @@ def makeConflictResponse(operation, retrievedlock, lock, oldlock, filename, reas
if reason:
resp.headers['X-WOPI-LockFailureReason'] = resp.data = reason
resp.status_code = http.client.CONFLICT
log.warning('msg="%s" filename="%s" token="%s" lock="%s" oldlock="%s" retrievedLock="%s" %s' %
log.warning('msg="%s: conflict" filename="%s" token="%s" lock="%s" oldlock="%s" retrievedlock="%s" reason="%s"' %
(operation.title(), filename, flask.request.args['access_token'][-20:], \
lock, oldlock, retrievedlock, ('reason="%s"' % reason if reason else 'result="conflict"')))
lock, oldlock, retrievedlock, (reason if reason else 'N/A')))
return resp


Expand Down
18 changes: 9 additions & 9 deletions src/core/xrootiface.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
EOSVERSIONPREFIX = '.sys.v#.'

ENOENT_MSG = 'No such file or directory'
EXCL_XATTR_MSG = 'exclusive set for existing attribute'

LOCKKEY = 'iop.lock' # this is to be compatible with the (future) Lock API in Reva

Expand Down Expand Up @@ -89,8 +90,8 @@ def _xrootcmd(endpoint, cmd, subcmd, userid, args):
if rc != '0':
# failure: get info from stderr, log and raise
msg = res[1][res[1].find('=')+1:].strip('\n')
if ENOENT_MSG.lower() in msg:
log.info('msg="Invoked xroot on non-existing file" cmd="%s" subcmd="%s" args="%s" error="%s" rc="%s"' % \
if ENOENT_MSG.lower() in msg or 'unable to get attribute' in msg or EXCL_XATTR_MSG in msg:
log.info('msg="Invoked xroot on non-existing entity" cmd="%s" subcmd="%s" args="%s" error="%s" rc="%s"' % \
(cmd, subcmd, args, msg, rc.strip('\00')))
else:
log.error('msg="Error with xroot" cmd="%s" subcmd="%s" args="%s" error="%s" rc="%s"' % \
Expand Down Expand Up @@ -246,12 +247,11 @@ def setxattr(endpoint, filepath, userid, key, value):

def getxattr(endpoint, filepath, userid, key):
'''Get the extended attribute <key> via a special open on behalf of the given userid'''
res = _xrootcmd(endpoint, 'attr', 'get', userid, 'mgm.attr.key=user.' + key + '&mgm.path=' + _getfilepath(filepath, encodeamp=True))
# if no error, the response comes in the format <key>="<value>"
try:
res = _xrootcmd(endpoint, 'attr', 'get', userid, 'mgm.attr.key=user.' + key + '&mgm.path=' + _getfilepath(filepath, encodeamp=True))
# if no error, the response comes in the format <key>="<value>"
return res.split('"')[1]
except IndexError:
log.warning('msg="Failed to getxattr" filepath="%s" key="%s" res="%s"' % (filepath, key, res))
except (IndexError, IOError):
return None


Expand All @@ -261,11 +261,11 @@ def rmxattr(endpoint, filepath, userid, key):


def setlock(endpoint, filepath, userid, value):
'''Set the lock as an xattr with the special option "c" (create-if-not-exists) on behalf of the given userid'''
'''Set a lock as an xattr with the special option "c" (create-if-not-exists) on behalf of the given userid'''
try:
setxattr(endpoint, filepath, userid, LOCKKEY, str(value) + '&mgm.option=c')
except IOError as e:
if 'exclusive set for exsisting attribute' in str(e):
if EXCL_XATTR_MSG in str(e):
raise IOError('File exists and islock flag requested')


Expand All @@ -283,7 +283,7 @@ def refreshlock(endpoint, filepath, userid, value):


def unlock(endpoint, filepath, userid):
'''Remove the lock as an xattr on behalf of the given userid'''
'''Remove a lock as an xattr on behalf of the given userid'''
rmxattr(endpoint, filepath, userid, LOCKKEY)


Expand Down

0 comments on commit 16ff754

Please sign in to comment.