Fix empty ignore pattern (#496)

This commit is contained in:
Zoe Roux 2024-05-14 23:06:59 +02:00 committed by GitHub
parent b6e0b5b328
commit a44b66caa9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 6 deletions

View File

@ -12,7 +12,7 @@ async def monitor(path: str, publisher: Publisher, client: KyooClient):
ignore_pattern = get_ignore_pattern()
async for changes in awatch(path, ignore_permission_denied=True):
for event, file in changes:
if ignore_pattern.match(file):
if ignore_pattern and ignore_pattern.match(file):
logger.info(
"Ignoring event %s for file %s (due to IGNORE_PATTERN)", event, file
)

View File

@ -12,10 +12,13 @@ logger = getLogger(__name__)
def get_ignore_pattern():
try:
return re.compile(os.environ.get("LIBRARY_IGNORE_PATTERN", ""))
pattern = os.environ.get("LIBRARY_IGNORE_PATTERN")
if pattern:
return re.compile(pattern)
return None
except Exception as e:
logger.error(f"Invalid ignore pattern. Ignoring. Error: {e}")
return re.compile("")
return None
async def scan(
@ -30,9 +33,10 @@ async def scan(
videos = [
os.path.join(dir, file) for dir, _, files in os.walk(path) for file in files
]
to_register = [
p for p in videos if p not in registered and not ignore_pattern.match(p)
]
if ignore_pattern is not None:
logger.info(f"Ignoring with pattern {ignore_pattern}")
videos = [p for p in videos if not ignore_pattern.match(p)]
to_register = [p for p in videos if p not in registered]
if remove_deleted:
deleted = [x for x in registered if x not in videos]