diff --git a/src/controllers/default.py b/src/controllers/default.py index 1b7b9a0d..0ea8ccbd 100644 --- a/src/controllers/default.py +++ b/src/controllers/default.py @@ -105,8 +105,8 @@ async def get_stats(_: Request): payload = {} with db.Session() as session: - movies_symlinks = session.execute(select(func.count(Movie._id)).where(Movie.symlinked is True)).scalar_one() - episodes_symlinks = session.execute(select(func.count(Episode._id)).where(Episode.symlinked is True)).scalar_one() + movies_symlinks = session.execute(select(func.count(Movie._id)).where(Movie.symlinked == True)).scalar_one() + episodes_symlinks = session.execute(select(func.count(Episode._id)).where(Episode.symlinked == True)).scalar_one() total_symlinks = movies_symlinks + episodes_symlinks total_movies = session.execute(select(func.count(Movie._id))).scalar_one() diff --git a/src/program/db/db_functions.py b/src/program/db/db_functions.py index 1bd1a286..431c6d6d 100644 --- a/src/program/db/db_functions.py +++ b/src/program/db/db_functions.py @@ -131,3 +131,5 @@ def run_delete(_type): run_delete(Movie) run_delete(MediaItem) + logger.log("PROGRAM", "Database reset. Turning off HARD_RESET Env Var.") + os.environ["HARD_RESET"] = "False" diff --git a/src/program/program.py b/src/program/program.py index 9ab6727f..e1ac5d5f 100644 --- a/src/program/program.py +++ b/src/program/program.py @@ -159,8 +159,8 @@ def start(self): logger.debug(f"Mapped metadata to {item.type.title()}: {item.log_string}") session.commit() - movies_symlinks = session.execute(select(func.count(Movie._id)).where(Movie.symlinked is True)).scalar_one() - episodes_symlinks = session.execute(select(func.count(Episode._id)).where(Episode.symlinked is True)).scalar_one() + movies_symlinks = session.execute(select(func.count(Movie._id)).where(Movie.symlinked == True)).scalar_one() # noqa + episodes_symlinks = session.execute(select(func.count(Episode._id)).where(Episode.symlinked == True)).scalar_one() # noqa total_symlinks = movies_symlinks + episodes_symlinks total_movies = session.execute(select(func.count(Movie._id))).scalar_one() total_shows = session.execute(select(func.count(Show._id))).scalar_one() diff --git a/src/program/symlink.py b/src/program/symlink.py index f79578b0..b7da2efb 100644 --- a/src/program/symlink.py +++ b/src/program/symlink.py @@ -242,14 +242,10 @@ def _symlink(self, item: Union[Movie, Episode]) -> bool: if os.path.islink(destination): os.remove(destination) os.symlink(source, destination) - item.set("symlinked", True) - item.set("symlinked_at", datetime.now()) - item.set("symlinked_times", item.symlinked_times + 1) except PermissionError as e: # This still creates the symlinks, however they will have wrong perms. User needs to fix their permissions. # TODO: Maybe we validate symlink class by symlinking a test file, then try removing it and see if it still exists - logger.error(f"Permission denied when creating symlink for {item.log_string}: {e}") - return True + logger.exception(f"Permission denied when creating symlink for {item.log_string}: {e}") except OSError as e: if e.errno == 36: # This will cause a loop if it hits this.. users will need to fix their paths @@ -259,11 +255,19 @@ def _symlink(self, item: Union[Movie, Episode]) -> bool: logger.error(f"OS error when creating symlink for {item.log_string}: {e}") return False - # Validate the symlink - if not os.path.islink(destination) or not os.path.exists(destination): - logger.error(f"Symlink validation failed for {item.log_string} from source: {source} to destination: {destination}") + if not os.path.islink(destination): + logger.error(f"Symlink validation failed: {destination} is not a symlink for {item.log_string}") + return False + if os.readlink(destination) != source: + logger.error(f"Symlink validation failed: {destination} does not point to {source} for {item.log_string}") + return False + if not os.path.isfile(destination): + logger.error(f"Symlink validation failed: {destination} is not a valid file for {item.log_string}") return False + item.set("symlinked", True) + item.set("symlinked_at", datetime.now()) + item.set("symlinked_times", item.symlinked_times + 1) return True def _create_item_folders(self, item: Union[Movie, Show, Season, Episode], filename: str) -> str: