Skip to content

Commit

Permalink
Ensure webconflict files can be written also when user has no access …
Browse files Browse the repository at this point in the history
…to the folder
  • Loading branch information
glpatcern committed Nov 29, 2021
1 parent b5cb24c commit f67481f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/core/wopi.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,14 @@ def putFile(fileid):
newname, ext = os.path.splitext(acctok['filename'])
# !!! typical EFSS formats are like '<filename>_conflict-<date>-<time>', but they're not synchronized back !!!
newname = '%s-webconflict-%s%s' % (newname, time.strftime('%Y%m%d-%H'), ext.strip())
utils.storeWopiFile(flask.request, retrievedLock, acctok, utils.LASTSAVETIMEKEY, newname)
try:
utils.storeWopiFile(flask.request, retrievedLock, acctok, utils.LASTSAVETIMEKEY, newname)
except IOError as e:
if utils.ACCESS_ERROR in str(e):
# let's try the user's home instead of the current folder
newname = utils.getuserhome(acctok['username']) + os.path.sep + os.path.basename(newname)
utils.storeWopiFile(flask.request, retrievedLock, acctok, utils.LASTSAVETIMEKEY, newname)

# keep track of this action in the original file's xattr, to avoid looping (see below)
st.setxattr(acctok['endpoint'], acctok['filename'], acctok['userid'], utils.LASTSAVETIMEKEY, 0)
log.info('msg="Conflicting copy created" user="%s" savetime="%s" lastmtime="%s" newfilename="%s" token="%s"' %
Expand Down
7 changes: 6 additions & 1 deletion src/core/wopiutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,9 @@ def storeWopiFile(request, retrievedlock, acctok, xakey, targetname=''):
st.setxattr(acctok['endpoint'], targetname, acctok['userid'], xakey, int(time.time()))
# and reinstate the lock if existing
if retrievedlock:
st.setlock(acctok['endpoint'], targetname, acctok['userid'], _makeLock(retrievedlock))
st.setlock(acctok['endpoint'], targetname, acctok['userid'], _makeLock(retrievedlock))


def getuserhome(username):
'''Returns the path to the "home" directory for a given user. CERN/EOS-specific, to be removed once locking is fully implemented.'''
return '/eos/user/%s/%s' % (username[0], username)

0 comments on commit f67481f

Please sign in to comment.