Example #1
0
def remove_shared_path_from_db(path: str):
    app.logger.info(f"Removing all record with abs_path starting with: {path}")

    removed_dirs = 0
    removed_files = 0

    entry_files, entry_dirs = CommonQuery.query_all_by_absolute_path(path)
    for entry in entry_files:
        db.session.delete(entry)
        removed_files += 1

    for entry in entry_dirs:
        db.session.delete(entry)
        removed_dirs += 1

    app.logger.info(
        f"About to commit a total of {removed_files + removed_dirs} less records. {removed_files} less file records. {removed_dirs} less dir records."
    )
Example #2
0
def _match_for_removed_item_and_delete(directory: str):
    """checks for any deleted file from the database
        if a file was deleted on the filesystem, it will
        delete the record for the database

    Arguments:
        directory {str} -- the path to check for any deleted files
    """
    files_entry, dirs_entry = CommonQuery.query_all_by_absolute_path(directory)
    for entry in files_entry:
        if not os.path.exists(entry):
            app.logger.debug(
                f"Found missing directory with path: {entry.abs_path}")
            db.session.delete(entry)

    for entry in dirs_entry:
        if not os.path.exists(entry):
            app.logger.debug(f"Found missing file with path: {entry.abs_path}")
            db.session.delete(entry)