|
2 | 2 | import posixpath |
3 | 3 | import logging |
4 | 4 | import threading |
| 5 | +import re |
5 | 6 |
|
6 | 7 | from funcy import retry, compose, decorator, wrap_with |
7 | 8 | from funcy.py3 import cat |
@@ -68,6 +69,16 @@ def __init__(self, repo, config): |
68 | 69 | super().__init__(repo, config) |
69 | 70 | self.no_traverse = False |
70 | 71 | self.path_info = self.path_cls(config[Config.SECTION_REMOTE_URL]) |
| 72 | + |
| 73 | + bucket = re.search( |
| 74 | + "{}://(.*)".format(self.scheme), |
| 75 | + config[Config.SECTION_REMOTE_URL], |
| 76 | + re.IGNORECASE, |
| 77 | + ) |
| 78 | + self.bucket = ( |
| 79 | + bucket.group(1).split("/")[0] if bucket else self.path_info.bucket |
| 80 | + ) |
| 81 | + |
71 | 82 | self.config = config |
72 | 83 | self.init_drive() |
73 | 84 |
|
@@ -144,7 +155,7 @@ def cache_root_dirs(self): |
144 | 155 | cached_dirs = {} |
145 | 156 | cached_ids = {} |
146 | 157 | for dir1 in self.gdrive_list_item( |
147 | | - "'{}' in parents and trashed=false".format(self.root_id) |
| 158 | + "'{}' in parents and trashed=false".format(self.remote_root_id) |
148 | 159 | ): |
149 | 160 | remote_path = posixpath.join(self.path_info.path, dir1["title"]) |
150 | 161 | cached_dirs.setdefault(remote_path, []).append(dir1["id"]) |
@@ -227,7 +238,9 @@ def drive(self): |
227 | 238 |
|
228 | 239 | self._gdrive = GoogleDrive(gauth) |
229 | 240 |
|
230 | | - self.root_id = self.get_remote_id(self.path_info, create=True) |
| 241 | + self.remote_root_id = self.get_remote_id( |
| 242 | + self.path_info, create=True |
| 243 | + ) |
231 | 244 | self._cached_dirs, self._cached_ids = self.cache_root_dirs() |
232 | 245 |
|
233 | 246 | return self._gdrive |
@@ -261,7 +274,7 @@ def get_remote_item(self, name, parents_ids): |
261 | 274 | return next(iter(item_list), None) |
262 | 275 |
|
263 | 276 | def resolve_remote_item_from_path(self, path_parts, create): |
264 | | - parents_ids = ["root"] |
| 277 | + parents_ids = [self.bucket] |
265 | 278 | current_path = "" |
266 | 279 | for path_part in path_parts: |
267 | 280 | current_path = posixpath.join(current_path, path_part) |
|
0 commit comments