In QGIS, I've tried to remove a layer, execute a processing and overwrite the input layer. This in my Python code:
from qgis.core import *
for lyr in QgsProject.instance().mapLayers().values():
if lyr.name() == "test":
QgsProject.instance().removeMapLayers([lyr.id()])
infn = QgsProject.instance().homePath()+"/temp.shp"
outfn = QgsProject.instance().homePath()+"/temp.shp"
processing.run("native:refactorfields", {'INPUT':infn,\
'FIELDS_MAPPING':[{'expression': '\"Field1\"','length': 10,'name': 'Field1','precision': 0,'type': 10},\
{'expression': '\"Field2\"','length': 50,'name': 'Field2','precision': 0,'type': 10}],\
'OUTPUT':outfn})
The layer is successfully removed from the legend but I received this error for the output file:
error OGR: C:/temp/temp.shp is not a directory.
It would seem as if the layer remained in memory and did not allow to overwrite.
Any help?