Skip to content

Commit ecbb692

Browse files
committed
perf: increase the judgment when obtaining files
1 parent 218cc5a commit ecbb692

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

owncloud/owncloud.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,23 @@ def get_file(self, remote_path, local_file=None):
506506
self._webdav_url + parse.quote(self._encode_string(remote_path)),
507507
stream=True
508508
)
509+
510+
path_split = list(filter(None, remote_path.split("/")))
511+
try:
512+
if len(path_split) > 1:
513+
file_list = [x.get_name() for x in self.list(self._normalize_path("/".join(path_split[0:-1])))]
514+
if path_split[-1] not in file_list:
515+
raise FileNotFoundError(f"Remote file {path_split[-1]} not exist, please check!")
516+
else:
517+
file_list = [x.get_name() for x in self.list(path="./")]
518+
if path_split[0] not in file_list:
519+
raise FileNotFoundError(f"Remote file {path_split[-1]} not exist, please check!")
520+
except HTTPResponseError as e:
521+
if e.status_code == 404:
522+
raise FileNotFoundError(f"Remote file {path_split[-1]} not exist, please check!")
523+
else:
524+
raise e
525+
509526
if res.status_code == 200:
510527
if local_file is None:
511528
# use downloaded file name from Content-Disposition

0 commit comments

Comments
 (0)