# HG changeset patch # User Goffi # Date 1600371679 -7200 # Node ID 02583a401e514a73023ea3aa99a27f5f1c1fad51 # Parent 43e60c40de651f0db3317a280776bc31130035a7 plugin XEP-0329: fix conflict check + directory creation in `onComponentCreateDir` diff -r 43e60c40de65 -r 02583a401e51 sat/plugins/plugin_xep_0329.py --- a/sat/plugins/plugin_xep_0329.py Thu Sep 17 21:40:23 2020 +0200 +++ b/sat/plugins/plugin_xep_0329.py Thu Sep 17 21:41:19 2020 +0200 @@ -1098,26 +1098,22 @@ 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 @@ 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(