Update the output filename (preferred_filename) so that we can notify it correctly to the user

This commit is contained in:
Gustavo Moreira
2024-06-10 18:37:38 +10:00
parent ab84070df3
commit 77fb0b7b26
2 changed files with 13 additions and 1 deletions
+9 -1
View File
@@ -789,8 +789,16 @@ class CommandLine:
if self._file.closed:
return None
self._file.close()
output_filename = self._get_final_filename()
# Update the filename, which may have changed if a file with
# the same name already existed. This needs to be done before
# closing the file, otherwise FileHandlerInterface will raise
# an exception. Also, the preferred_filename setter only allows
# a specific set of characters, where '/' is not in that list
self.preferred_filename = os.path.basename(output_filename)
self._file.close()
os.rename(self._name, output_filename)
if direct:
@@ -115,6 +115,10 @@ class LayerWriter(plugins.PluginInterface):
progress_callback=self._progress_callback,
)
file_handle.close()
# Update the filename, which may have changed if a file
# with the same name already existed.
output_name = file_handle.preferred_filename
except IOError as excp:
yield 0, (f"Layer cannot be written to {output_name}: {excp}",)