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

Fix some issues to work on my ceiba #16

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion ceiba_dl/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import pycurl
import urllib.parse

from pathvalidate import sanitize_filepath
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

請仿照其他檔案,把所有的 from ... import ... 排在一起,並照字母排序。

由於 pathvalidate 不在 Python 標準函式庫中,需要額外安裝才能使用,因此請一併修改 README.asciidocconfigure.acrequirements.txt 讓使用者知道這件事。


class Error(Exception):
def __str__(self):
return self.message
Expand Down Expand Up @@ -237,6 +239,7 @@ def download_file(self, path, retry, dcb, ecb):

def download_link(self, path, node, retry, dcb, ecb):
disk_path_object = pathlib.Path(path.lstrip('/'))
disk_path_object = pathlib.Path(sanitize_filepath(str(disk_path_object)))
disk_path = str(disk_path_object)
if self.vfs.is_internal_link(node):
link_target_path = str(pathlib.PurePath(node.read_link()))
Expand Down Expand Up @@ -283,7 +286,8 @@ def download_link(self, path, node, retry, dcb, ecb):

def download_regular(self, path, node, retry, dcb, ecb):
disk_path_object = pathlib.Path(path.lstrip('/'))

disk_path_object = pathlib.Path(sanitize_filepath(str(disk_path_object)))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如同我在 #15 (comment) 所說,我覺得這個可以移入 disk_path_object_open,只在檔名真的造成問題的時候才使用 sanitize_filepath。至於特殊字元的處理方式,我覺得可以比照現在 / 替換成 _ 的模式,看是要替換成 _ 還是其他相似或全形的符號,而不要直接刪除。


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

請刪除行尾空白。

def ccb(*args):
return dcb(path, *args)

Expand Down Expand Up @@ -355,6 +359,7 @@ def disk_path_object_open(mode):

def download_directory(self, path, node, retry, dcb, ecb):
disk_path_object = pathlib.Path(path.lstrip('/'))
disk_path_object = pathlib.Path(sanitize_filepath(str(disk_path_object)))
if disk_path_object.is_dir():
self.logger.info('跳過已經存在的資料夾 {}' \
.format(str(disk_path_object)))
Expand Down