Skip to content
Open
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
32 changes: 31 additions & 1 deletion duplicity/backends/dpbxbackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ def __init__(self, parsed_url):
self.auth_flow = None

self.login()

def user_authenticated(self):
try:
account = self.api_client.users_get_current_account()
log.Debug("User authenticated as ,%s" % account)
return True
except:
log.Debug('User not authenticated')
return False
def load_access_token(self):
return os.environ.get('DPBX_ACCESS_TOKEN', None)

Expand Down Expand Up @@ -196,10 +203,14 @@ def _put(self, source_path, remote_filename):
(res_metadata.size, file_size))

def put_file_small(self, source_path, remote_path):
if not self.user_authenticated():
self.login()

file_size = os.path.getsize(source_path.name)
f = source_path.open('rb')
try:
log.Debug('dpbx,files_upload(%s, [%d bytes])' % (remote_path, file_size))

res_metadata = self.api_client.files_upload(f, remote_path,
mode=WriteMode.overwrite,
autorename=False,
Expand All @@ -212,6 +223,9 @@ def put_file_small(self, source_path, remote_path):
f.close()

def put_file_chunked(self, source_path, remote_path):
if not self.user_authenticated():
self.login()

file_size = os.path.getsize(source_path.name)
f = source_path.open('rb')
try:
Expand Down Expand Up @@ -295,6 +309,10 @@ def put_file_chunked(self, source_path, remote_path):
log.Debug('dpbx,files_upload_session_append: %s' % e)

retry_number -= 1

if not self.user_authenticated():
self.login()

if retry_number == 0:
raise

Expand All @@ -320,6 +338,9 @@ def put_file_chunked(self, source_path, remote_path):

@command()
def _get(self, remote_filename, local_path):
if not self.user_authenticated():
self.login()

remote_dir = urllib.unquote(self.parsed_url.path.lstrip('/'))
remote_path = '/' + os.path.join(remote_dir, remote_filename).rstrip()

Expand Down Expand Up @@ -353,6 +374,8 @@ def _get(self, remote_filename, local_path):
@command()
def _list(self):
# Do a long listing to avoid connection reset
if not self.user_authenticated():
self.login()
remote_dir = '/' + urllib.unquote(self.parsed_url.path.lstrip('/')).rstrip()

log.Debug('dpbx.files_list_folder(%s)' % remote_dir)
Expand All @@ -373,6 +396,9 @@ def _list(self):

@command()
def _delete(self, filename):
if not self.user_authenticated():
self.login()

remote_dir = urllib.unquote(self.parsed_url.path.lstrip('/'))
remote_path = '/' + os.path.join(remote_dir, filename).rstrip()

Expand All @@ -390,6 +416,8 @@ def _close(self):

@command()
def _query(self, filename):
if not self.user_authenticated():
self.login()
remote_dir = urllib.unquote(self.parsed_url.path.lstrip('/'))
remote_path = '/' + os.path.join(remote_dir, filename).rstrip()

Expand All @@ -399,6 +427,8 @@ def _query(self, filename):
return {'size': info.size}

def check_renamed_files(self, file_list):
if not self.user_authenticated():
self.login()
bad_list = [x for x in file_list if DPBX_AUTORENAMED_FILE_RE.search(x) is not None]
if len(bad_list) == 0:
return
Expand Down