dimberman commented on code in PR #29694:
URL: https://github.com/apache/airflow/pull/29694#discussion_r1118985060
##########
airflow/providers/google/suite/hooks/drive.py:
##########
@@ -159,6 +160,46 @@ def exists(
)
)
+ def _resolve_file_path(self, file_id: str) -> str:
+ """
+ Returns the full Google Drive path for given file_id
+
+ :param file_id: The id of a file in Google Drive
+ :return: Google Drive full path for a file
+ """
+ MAX_NESTED_FOLDERS_LEVEL = 20 # Link to docs
https://support.google.com/a/users/answer/7338880?hl=en
+ iteration = 1
+
+ service = self.get_conn()
+ has_reached_root = False
+ _file_id = file_id
+ path: str = ""
+ while not has_reached_root:
+ file_info = (
+ service.files()
+ .get(
+ fileId=_file_id,
+ fields="id,name,parents",
+ supportsAllDrives=True,
+ )
+ .execute()
+ )
+ if "parents" in file_info:
+ parent_directories = file_info["parents"]
+ path = f'{file_info["name"]}' if path == "" else
f'{file_info["name"]}/{path}'
+
+ if len(parent_directories) > 1:
+ self.log.warning("Google returned multiple parents,
picking first")
+ _file_id = parent_directories[0]
+ else:
+ has_reached_root = True
+ path = f'{file_info["name"]}/{path}'
Review Comment:
Looks great!
--
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]