comparison sat/plugins/plugin_xep_0329.py @ 3500:73b8a8d938be

plugin XEP-0329: check files conflict also for root files
author Goffi <goffi@goffi.org>
date Fri, 16 Apr 2021 18:32:40 +0200
parents be6d91572633
children e47aa1fb7b24
comparison
equal deleted inserted replaced
3499:a83a04b7394b 3500:73b8a8d938be
1084 f"path: {path}\nnamespace: {namespace!r}" 1084 f"path: {path}\nnamespace: {namespace!r}"
1085 ) 1085 )
1086 client.sendError(iq_elt, 'forbidden', "You can't create a directory there") 1086 client.sendError(iq_elt, 'forbidden', "You can't create a directory there")
1087 return 1087 return
1088 # when going further into the path, the permissions will be checked by getFiles 1088 # when going further into the path, the permissions will be checked by getFiles
1089 if len(path.parts) > 2: 1089 files_data = await self.host.memory.getFiles(
1090 files_data = await self.host.memory.getFiles( 1090 client,
1091 client, 1091 peer_jid=peer_jid,
1092 peer_jid=peer_jid, 1092 path=path.parent,
1093 path=path.parent, 1093 namespace=namespace,
1094 namespace=namespace, 1094 owner=owner,
1095 owner=owner, 1095 )
1096 ) 1096 if path.name in [d['name'] for d in files_data]:
1097 if path.name in [d['name'] for d in files_data]: 1097 log.warning(
1098 log.warning( 1098 f"Conflict when trying to create a directory (from: {peer_jid} "
1099 f"Conflict when trying to create a directory (from: {peer_jid} " 1099 f"namespace: {namespace!r} path: {path!r})"
1100 f"namespace: {namespace!r} path: {path!r})" 1100 )
1101 ) 1101 client.sendError(
1102 client.sendError( 1102 iq_elt, 'conflict', "there is already a file or dir at this path")
1103 iq_elt, 'conflict', "there is already a file or dir at this path") 1103 return
1104 return
1105 1104
1106 try: 1105 try:
1107 configuration_elt = next( 1106 configuration_elt = next(
1108 create_dir_elt.elements(NS_FIS_CONFIGURATION, 'configuration')) 1107 create_dir_elt.elements(NS_FIS_CONFIGURATION, 'configuration'))
1109 except StopIteration: 1108 except StopIteration: