skyzh / canvas_grab

🌐 One-click script to synchronize files from Canvas LMS.
https://git.sjtu.edu.cn/iskyzh/canvas_grab
MIT License
209 stars 28 forks source link

Escape characters in course names #149

Closed squnit closed 3 years ago

squnit commented 3 years ago

A course name may possibly contain any of the characters

\ / : ? " < > |

Creating a directory corresponding to the course name1 | name2 on Windows results in

Traceback (most recent call last):
  File "main.py", line 6, in <module>
    canvas_grab.__main__.main()
  File "C:\Users\username\canvas_grab\canvas_grab\__main__.py", line 45, in main
    on_disk_snapshot = canvas_grab.snapshot.OnDiskSnapshot(
  File "C:\Users\username\canvas_grab\canvas_grab\snapshot\on_disk_snapshot.py", line 29, in take_snapshot
    for item in base.rglob('*'):
  File "C:\Python38\lib\pathlib.py", line 1130, in rglob
    for p in selector.select_from(self):
  File "C:\Python38\lib\pathlib.py", line 486, in select_from
    if not is_dir(parent_path):
  File "C:\Python38\lib\pathlib.py", line 1385, in is_dir
    return S_ISDIR(self.stat().st_mode)
  File "C:\Python38\lib\pathlib.py", line 1176, in stat
    return self._accessor.stat(self)
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'files\\name1 | name2'
skyzh commented 3 years ago

Seems that https://github.com/skyzh/canvas_grab/blob/master/canvas_grab/utils.py#L38 has already handled this case. I'll look into this soon.

skyzh commented 3 years ago

canvas_grab on latest master should have fixed this issue. This problem will only happen when course names could not be parsed with SJTU course name style. Thanks for your report! If there's any further issue, feel free to reopen this issue.