Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't split keys in objwrapper #85

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions objwrapper/alioss.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ def get_name(self):

def list_objs(self, prefix=None):
for key in oss2.ObjectIterator(self.bucket, prefix=prefix):
token = key.key.split('/', 1)
if len(token) == 2:
token = key.key
if token:
size = key.size
obj = [token[0], token[1], size]
obj = [token, size]
yield obj

def obj_exists(self, key):
Expand Down
6 changes: 3 additions & 3 deletions objwrapper/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def list_objs(self, prefix=None):
iterator = paginator.paginate(Bucket=self.bucket)
for page in iterator:
for content in page.get('Contents', []):
tokens = content.get('Key', '').split('/', 1)
if len(tokens) == 2:
obj = [tokens[0], tokens[1], content.get('Size', 0)]
tokens = content.get('Key', '')
if tokens:
obj = [tokens, content.get('Size', 0)]
yield obj


Expand Down
7 changes: 6 additions & 1 deletion seafobj/backends/alioss.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ def get_name(self):
return 'OSS storage backend'

def list_objs(self, repo_id=None):
return self.oss_client.list_objs(repo_id)
objs = self.oss_client.list_objs(repo_id)
for obj in objs:
tokens = obj[0].split('/', 1)
if len(tokens) == 2:
newobj = [tokens[0], tokens[1], obj[1]]
yield newobj

def obj_exists(self, repo_id, obj_id):
key = '%s/%s' % (repo_id, obj_id)
Expand Down
7 changes: 6 additions & 1 deletion seafobj/backends/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ def get_name(self):
return 'S3 storage backend'

def list_objs(self, repo_id=None):
return self.s3_client.list_objs(repo_id)
objs = self.s3_client.list_objs(repo_id)
for obj in objs:
tokens = obj[0].split('/', 1)
if len(tokens) == 2:
newobj = [tokens[0], tokens[1], obj[1]]
yield newobj

def obj_exists(self, repo_id, obj_id):
s3_path = '%s/%s' % (repo_id, obj_id)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_objwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ def read_and_write_client(client):
objs = client.list_objs()
num = 0
for obj in objs:
obj = obj[0].split('/', 1)
if len(obj) != 2:
continue
if obj[0] == repo_id1 or obj[0] == repo_id2:
num += 1
assert num == 3

objs = client.list_objs(repo_id1)
num = 0
for obj in objs:
obj = obj[0].split('/', 1)
if len(obj) != 2:
continue
assert obj[0] == repo_id1
assert obj[1] == '249408dcc7aaba6e0948cb2d1950aaf4c86078b0' or obj[1] == '8228f1d3877efa3395475ccccd065f87d7727e29'
num += 1
Expand All @@ -44,6 +50,9 @@ def read_and_write_client(client):
objs = client.list_objs(repo_id2)
num = 0
for obj in objs:
obj = obj[0].split('/', 1)
if len(obj) != 2:
continue
assert obj[0] == repo_id2
assert obj[1] == '97c5a757b1aa4de4a9d7c07f3d66648e43c562e7'
num += 1
Expand Down
Loading