Skip to content

Commit ef4fa2b

Browse files
committed
fix following symlinks
1 parent e6da0d2 commit ef4fa2b

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

comiclib/scan.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import importlib
2+
import itertools
3+
import os
24
import sys
35
import copy
46
import hashlib
@@ -34,8 +36,8 @@
3436

3537
def scan(paths):
3638
with Session(engine) as db:
37-
for p in paths: # TODO: https://github.com/python/cpython/issues/77609
38-
p = Path(p).resolve().relative_to(Path(settings.content).resolve())
39+
for p in paths:
40+
p = Path(os.path.relpath(p, settings.content))
3941
if p.is_relative_to('thumb'):
4042
continue
4143
old_a = db.scalar(select(Archive).where(
@@ -100,7 +102,7 @@ def watch():
100102
for _, fname in changes:
101103
try:
102104
if _check_inuse:
103-
if fname not in get_files_inuse():
105+
if Path(fname).resolve() not in get_files_inuse():
104106
scan([fname])
105107
else:
106108
while file_sizes.get(fname, -1) != (fsize := Path(fname).stat().st_size):
@@ -112,4 +114,7 @@ def watch():
112114

113115

114116
def scannow():
115-
scan(Path(settings.content).rglob('*'))
117+
# TODO: https://github.com/python/cpython/issues/77609
118+
scan(itertools.chain.from_iterable(
119+
itertools.chain((Path(dirpath)/dirname for dirname in dirnames), (Path(dirpath)/filename for filename in filenames)) for dirpath, dirnames, filenames in os.walk(settings.content, followlinks=True))
120+
)

docs/en/docs/settings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The following is a list of available settings:
2828
| ------- | ---- | ----- |
2929
| `debug` | Turn on debug output (`True`/`False`) | `False` |
3030
| `loglevel` | Log level (`DEBUG`/`INFO`/`WARNING`/`ERROR`/`CRITICAL`). If `debug` is `True`, it will be overwritten to `DEBUG` | `INFO` |
31-
| `content` | The path where the comic file is stored (due to [a problem with Python](https://github.com/python/cpython/issues/77609), following symbolic links is not currently supported) | `.` |
31+
| `content` | The path where the comic file is stored | `.` |
3232
| `thumb` | The path where the generated thumbnails are stored | `./thumb`|
3333
| `metadata` | The URL for metadata database, refer to [SQLAlchemy documentation](https://docs.sqlalchemy.org/en/20/core/engines.html#database-urls) | `sqlite:///./comiclib_metadata.db` |
3434
| `password` | Admin password. If it is `None`, any visitor will have editing permissions. This feature is designed to protect against gentlemen but not villains. If you need security protection, please use e.g. the HTTP basic authentication of the reverse proxy, Cloudflare Access or TLS client certificate, etc. | `None`|

docs/zh/docs/settings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
| ------- | ---- | ----- |
2929
| `debug` | 开启调试输出(`True`/`False`| `False` |
3030
| `loglevel` | 日志级别(`DEBUG`/`INFO`/`WARNING`/`ERROR`/`CRITICAL`),若`debug``True`,会被覆盖为`DEBUG` | `INFO` |
31-
| `content` | 漫画文件存放的路径(由于 [Python 的一个问题](https://github.com/python/cpython/issues/77609),暂不支持跟随符号链接) | `.` |
31+
| `content` | 漫画文件存放的路径 | `.` |
3232
| `thumb` | 生成的缩略图存放的路径 | `./thumb`|
3333
| `metadata` | 元数据库 URL,参考[SQLAlchemy 文档](https://docs.sqlalchemy.org/en/20/core/engines.html#database-urls) | `sqlite:///./comiclib_metadata.db` |
3434
| `password` | 管理密码,若为`None`则任何访客皆可编辑。此功能防君子不防小人,若需安全保护请借助反向代理的 HTTP 基本验证、Cloudflare Access 或 TLS 客户端证书等。| `None`|

0 commit comments

Comments
 (0)