Skip to content

Commit

Permalink
Implemented the paging for children for each directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixleong committed Mar 6, 2017
1 parent ab9cc09 commit ba1e456
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions onedrived/od_tasks/merge_dir.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import itertools
import logging
import os
import shutil

import onedrivesdk.error
from onedrivesdk import Item, Folder
from onedrivesdk import Item, Folder, ChildrenCollectionRequest
from send2trash import send2trash

from . import base
Expand Down Expand Up @@ -126,7 +127,25 @@ def handle(self):

if not self.assume_remote_unchanged or not self.parent_remote_unchanged:
try:
all_remote_items = item_request_call(self.repo, self.item_request.children.get)
remote_item_page = item_request_call(self.repo, self.item_request.children.get)
all_remote_items = remote_item_page

while True:
# HACK: ChildrenCollectionPage is not guaranteed to have
# the _next_page_link attribute and
# ChildrenCollectionPage.get_next_page_request doesn't
# implement the check correctly
if not hasattr(remote_item_page, '_next_page_link'):
break

logging.debug('Paging for more items: %s', self.rel_path)
remote_item_page = item_request_call(
self.repo,
ChildrenCollectionRequest.get_next_page_request(
remote_item_page,
self.repo.authenticator.client).get)
all_remote_items = itertools.chain(
all_remote_items, remote_item_page)
except onedrivesdk.error.OneDriveError as e:
logging.error('Encountered API Error: %s. Skip directory "%s".', e, self.rel_path)
return
Expand Down

0 comments on commit ba1e456

Please sign in to comment.