Returns a list of entries contained within a directory.
(self, dirname)
| 376 | return False |
| 377 | |
| 378 | def listdir(self, dirname): |
| 379 | """Returns a list of entries contained within a directory.""" |
| 380 | client = boto3.client("s3", endpoint_url=self._s3_endpoint) |
| 381 | bucket, path = self.bucket_and_path(dirname) |
| 382 | p = client.get_paginator("list_objects") |
| 383 | if not path.endswith("/"): |
| 384 | path += "/" # This will now only retrieve subdir content |
| 385 | keys = [] |
| 386 | for r in p.paginate(Bucket=bucket, Prefix=path, Delimiter="/"): |
| 387 | keys.extend( |
| 388 | o["Prefix"][len(path) : -1] for o in r.get("CommonPrefixes", []) |
| 389 | ) |
| 390 | for o in r.get("Contents", []): |
| 391 | key = o["Key"][len(path) :] |
| 392 | if key: # Skip the base dir, which would add an empty string |
| 393 | keys.append(key) |
| 394 | return keys |
| 395 | |
| 396 | def makedirs(self, dirname): |
| 397 | """Creates a directory and all parent/intermediate directories.""" |