Skip to content

Commit

Permalink
Fix empty ignore pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
zoriya committed May 14, 2024
1 parent b6e0b5b commit aa89263
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion scanner/scanner/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
14 changes: 9 additions & 5 deletions scanner/scanner/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@

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(
Expand All @@ -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]
Expand Down

0 comments on commit aa89263

Please sign in to comment.