plugin XEP-0329: fix conflict check + directory creation in onComponentCreateDir
This commit is contained in:
parent
280f86881a
commit
629901674b
1 changed files with 19 additions and 15 deletions
|
|
@ -1098,26 +1098,22 @@ class XEP_0329(object):
|
|||
client.sendError(iq_elt, 'forbidden', "You can't create a directory there")
|
||||
return
|
||||
# when going further into the path, the permissions will be checked by getFiles
|
||||
try:
|
||||
await self.host.memory.getFiles(
|
||||
if len(path.parts) > 2:
|
||||
files_data = await self.host.memory.getFiles(
|
||||
client,
|
||||
peer_jid=peer_jid,
|
||||
path=path.parent,
|
||||
name=path.name,
|
||||
namespace=namespace,
|
||||
owner=owner,
|
||||
)
|
||||
except exceptions.NotFound:
|
||||
# this is expected, nothing should be found at this path
|
||||
pass
|
||||
else:
|
||||
log.warning(
|
||||
f"Conflict when trying to create a directory (from: {peer_jid} "
|
||||
f"namespace: {namespace!r} path: {path!r})"
|
||||
)
|
||||
client.sendError(
|
||||
iq_elt, 'conflict', "there is already a file or dir at this path")
|
||||
return
|
||||
if path.name in [d['name'] for d in files_data]:
|
||||
log.warning(
|
||||
f"Conflict when trying to create a directory (from: {peer_jid} "
|
||||
f"namespace: {namespace!r} path: {path!r})"
|
||||
)
|
||||
client.sendError(
|
||||
iq_elt, 'conflict', "there is already a file or dir at this path")
|
||||
return
|
||||
|
||||
try:
|
||||
configuration_elt = next(
|
||||
|
|
@ -1125,7 +1121,15 @@ class XEP_0329(object):
|
|||
except StopIteration:
|
||||
configuration_elt = None
|
||||
|
||||
await self.host.memory.setFile(client, path.name, path=path.parent, namespace=namespace, owner=owner, peer_jid=peer_jid)
|
||||
await self.host.memory.setFile(
|
||||
client,
|
||||
path.name,
|
||||
path=path.parent,
|
||||
type_=C.FILE_TYPE_DIRECTORY,
|
||||
namespace=namespace,
|
||||
owner=owner,
|
||||
peer_jid=peer_jid
|
||||
)
|
||||
|
||||
if configuration_elt is not None:
|
||||
file_data = (await self.host.memory.getFiles(
|
||||
|
|
|
|||
Loading…
Reference in a new issue