Repository: topoteretes/cognee
File: cognee/tasks/ingestion/data_item_to_text_file.py (Python)

Code before:

        # data is local file path
        elif parsed_url.scheme == "file":
            if settings.accept_local_file_path:
                loader = get_loader_engine()
                return await loader.load_file(data_item_path, preferred_loaders), loader.get_loader(
                    data_item_path, preferred_loaders
                )
            else:
                raise IngestionError(message="Local files are not accepted.")

        # data is an absolute file path
        elif data_item_path.startswith("/") or (
            os.name == "nt" and len(data_item_path) > 1 and data_item_path[1] == ":"
        ):
            # Handle both Unix absolute paths (/path) and Windows absolute paths (C:\path)
            if settings.accept_local_file_path:
                loader = get_loader_engine()
                return await loader.load_file(data_item_path, preferred_loaders), loader.get_loader(
                    data_item_path, preferred_loaders
                )
            else:
                raise IngestionError(message="Local files are not accepted.")

        # data is a relative file path (e.g., "file.json", "data/file.txt")
        elif parsed_url.scheme == "" and not Path(data_item_path).is_absolute():
            # This is a relative file path - check if it exists and can be loaded
            if settings.accept_local_file_path:
                loader = get_loader_engine()
                return await loader.load_file(data_item_path, preferred_loaders), loader.get_loader(
                    data_item_path, preferred_loaders
                )
            else:
                raise IngestionError(message="Local files are not accepted.")

        # data has unsupported URL scheme or format
        else:
            raise IngestionError(message=f"Unsupported data source format: {data_item_path}")

    # data is not a supported type
    raise IngestionError(message=f"Data type not supported: {type(data_item_path)}")


Review comment (suggestion):
This is not the right place to add this handler for relative paths. It should be added here:

save_data_item_to_storage



Code after:

        # data is local file path
        elif parsed_url.scheme == "file":
            if settings.accept_local_file_path:
                loader = get_loader_engine()
                return await loader.load_file(data_item_path, preferred_loaders), loader.get_loader(
                    data_item_path, preferred_loaders
                )
            else:
                raise IngestionError(message="Local files are not accepted.")

        # data is an absolute file path
        elif data_item_path.startswith("/") or (
            os.name == "nt" and len(data_item_path) > 1 and data_item_path[1] == ":"
        ):
            # Handle both Unix absolute paths (/path) and Windows absolute paths (C:\path)
            if settings.accept_local_file_path:
                loader = get_loader_engine()
                return await loader.load_file(data_item_path, preferred_loaders), loader.get_loader(
                    data_item_path, preferred_loaders
                )
            else:
                raise IngestionError(message="Local files are not accepted.")

    # data is not a supported type
    raise IngestionError(message=f"Data type not supported: {type(data_item_path)}")