vaefremov95 commented on code in PR #62321:
URL: https://github.com/apache/airflow/pull/62321#discussion_r2854463088
##########
providers/imap/src/airflow/providers/imap/hooks/imap.py:
##########
@@ -310,11 +317,21 @@ def _correct_path(self, name: str,
local_output_directory: str) -> str:
else local_output_directory + "/" + name
)
- def _create_file(self, name: str, payload: Any, local_output_directory:
str) -> None:
- file_path = self._correct_path(name, local_output_directory)
-
- with open(file_path, "wb") as file:
- file.write(payload)
+ def _create_file(
+ self, name: str, payload: Any, local_output_directory: str,
overwrite_file: bool
+ ) -> None:
+ filename, extensions = name.split(".", 1)
Review Comment:
Thanks for the review!
Yes, you are right, files without an extension will raise a ValueError. I
was assuming we are dealing with email attachments, which 99.9% of the time
have an extension. I’ve never seen anyone send an attachment without extension.
However, I will add handling for the no-extension case and appropriate unit
test to make sure this case is properly covered.
I think that os.path.splitext is not suitable for files with multiple
extensions such as .tar.gz. It splits on the last extension, so file.tar.gz
would result in file.tar as the filename, which would then become
file.tar_1.gz. I will ad unit test to cover multiple extensions scenario.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]