Skip to content

[Bug] change the ROOT_DIR into system temp dir to avoid path errors in some cases #39

@Cesium01

Description

@Cesium01

The problem

When I try to package the application containing browserforge with pyinstaller, it keeps reporting local path resolving error. Turns out that browserforge uses relative path on ROOT_DIR in download part, and while packaging, pyinstaller uses system temp dir, which causes browserforge to resolve storage path to a folder in temp dir. And after packaging, pyinstaller will delete that folder.

I found that I needed to rewrite some code of browserforge to avoid this problem, so this issue came about.
Please reply if you have any questions.

In download.py

cache_path = os.path.join(tempfile.gettempdir(),"browserforge_cache")
ROOT_DIR: Path = Path(cache_path)
os.makedirs(ROOT_DIR, exist_ok=True)

"""Constants for headers and fingerprints data"""
DATA_DIRS: Dict[str, Path] = {
    "headers": ROOT_DIR / "headers/data",
    "fingerprints": ROOT_DIR / "fingerprints/data",
}
for path in DATA_DIRS.values():
    os.makedirs(path, exist_ok=True)

In fingerprints/generator.py

from browserforge.download import DATA_DIRS
...
DATA_DIR: Path = DATA_DIRS['fingerprints']

In headers/generator.py

from browserforge.download import DATA_DIRS
...
DATA_DIR: Path = DATA_DIRS['headers']

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions