bulk-downloader-for-reddit
bulk-downloader-for-reddit copied to clipboard
[BUG] bdfr attempts to write to default_config.cfg bundled with code on first run
- [X] I am reporting a bug.
- [X] I am running the latest version of BDfR
- [X] I have read the Opening an issue
Description
I'm in a process of packaging of bdfr
for NixOS. Nix stores all software a read-only filesystem and that fact uncovered the bug: bdfr
attempts to write to default_config.cfg
bundled with code on the first run.
Command
bdfr download ./2023-03-06/ --subreddit Python -L 10
Environment (please complete the following information)
- OS: NixOS (unstable)
- Python 3.10.10
Logs
The log wasn't generated, here's output of the command:
Downloader exited unexpectedly
Traceback (most recent call last):
File "/nix/store/gcj0r2gn5cw2dwx4q5mwvhqgsh93fjk1-bdfr-2.6.2/lib/python3.10/site-packages/bdfr/__main__.py", line 117, in cli_download
reddit_downloader = RedditDownloader(config, [stream])
File "/nix/store/gcj0r2gn5cw2dwx4q5mwvhqgsh93fjk1-bdfr-2.6.2/lib/python3.10/site-packages/bdfr/downloader.py", line 41, in __init__
super(RedditDownloader, self).__init__(args, logging_handlers)
File "/nix/store/gcj0r2gn5cw2dwx4q5mwvhqgsh93fjk1-bdfr-2.6.2/lib/python3.10/site-packages/bdfr/connector.py", line 59, in __init__
self.read_config()
File "/nix/store/gcj0r2gn5cw2dwx4q5mwvhqgsh93fjk1-bdfr-2.6.2/lib/python3.10/site-packages/bdfr/connector.py", line 122, in read_config
with Path(self.config_location).open(mode="w") as file:
File "/nix/store/iw1vmh509hcbby8dbpsaanbri4zsq7dj-python3-3.10.10/lib/python3.10/pathlib.py", line 1119, in open
return self._accessor.open(self, mode, buffering, encoding, errors,
OSError: [Errno 30] Read-only file system: '/nix/store/gcj0r2gn5cw2dwx4q5mwvhqgsh93fjk1-bdfr-2.6.2/lib/python3.10/site-packages/bdfr/default_config.cfg'
Traceback (most recent call last):
File "/nix/store/gcj0r2gn5cw2dwx4q5mwvhqgsh93fjk1-bdfr-2.6.2/bin/.bdfr-wrapped", line 9, in <module>
sys.exit(cli())
File "/nix/store/h5rimz2y6fy3irl98lszdnc4jv3fvv2k-python3.10-click-8.1.3/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/nix/store/h5rimz2y6fy3irl98lszdnc4jv3fvv2k-python3.10-click-8.1.3/lib/python3.10/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/nix/store/h5rimz2y6fy3irl98lszdnc4jv3fvv2k-python3.10-click-8.1.3/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/nix/store/h5rimz2y6fy3irl98lszdnc4jv3fvv2k-python3.10-click-8.1.3/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/nix/store/h5rimz2y6fy3irl98lszdnc4jv3fvv2k-python3.10-click-8.1.3/lib/python3.10/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/nix/store/h5rimz2y6fy3irl98lszdnc4jv3fvv2k-python3.10-click-8.1.3/lib/python3.10/site-packages/click/decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File "/nix/store/gcj0r2gn5cw2dwx4q5mwvhqgsh93fjk1-bdfr-2.6.2/lib/python3.10/site-packages/bdfr/__main__.py", line 117, in cli_download
reddit_downloader = RedditDownloader(config, [stream])
File "/nix/store/gcj0r2gn5cw2dwx4q5mwvhqgsh93fjk1-bdfr-2.6.2/lib/python3.10/site-packages/bdfr/downloader.py", line 41, in __init__
super(RedditDownloader, self).__init__(args, logging_handlers)
File "/nix/store/gcj0r2gn5cw2dwx4q5mwvhqgsh93fjk1-bdfr-2.6.2/lib/python3.10/site-packages/bdfr/connector.py", line 59, in __init__
self.read_config()
File "/nix/store/gcj0r2gn5cw2dwx4q5mwvhqgsh93fjk1-bdfr-2.6.2/lib/python3.10/site-packages/bdfr/connector.py", line 122, in read_config
with Path(self.config_location).open(mode="w") as file:
File "/nix/store/iw1vmh509hcbby8dbpsaanbri4zsq7dj-python3-3.10.10/lib/python3.10/pathlib.py", line 1119, in open
return self._accessor.open(self, mode, buffering, encoding, errors,
OSError: [Errno 30] Read-only file system: '/nix/store/gcj0r2gn5cw2dwx4q5mwvhqgsh93fjk1-bdfr-2.6.2/lib/python3.10/site-packages/bdfr/default_config.cfg'
Suspected cause and proposed solution
I think there's the culprit:
https://github.com/aliparlakci/bulk-downloader-for-reddit/blob/38e6c457920965760865859268a554854e90b380/bdfr/connector.py#L202-L205
Here's my humble attempt to fix (I'm not familiar with the rest of codebase):
if not self.config_location:
with importlib.resources.path("bdfr", "default_config.cfg") as default_config_path:
path = Path(self.config_directory, "default_config.cfg")
shutil.copy(default_config_path, path)
self.config_location = path