LordAmit/Brightness

Saving to a folder without permissions

golgor opened this issue · 1 comments

Describe the bug
After installing and trying to "save current setting", the default folder for saving the configuration in is the installation path. If trying to save in this folder, the whole application crashes without any notification in the GUI.

Running it from command line gave the error below, see Screenshots.

To Reproduce
Steps to reproduce the behavior:

  1. Start application.
  2. File -> save current setting.
  3. Try to save the setting file where the permissions is missing, such as the installation directory in most cases.
  4. Program crashes without any notification.

Expected behavior
It would be nice to catch this exception and rather show a messagebox saying that saving of the settings failed in the current location.

Screenshots

Qt: Session management error: networkIdsList argument is NULL
Traceback (most recent call last):
  File "/usr/share/brightness-controller/init.py", line 527, in save_settings
    WriteConfig.write_primary_display(
  File "/usr/share/brightness-controller/util/write_config.py", line 56, in write_primary_display
    with open(file_path, 'w+') as configfile:
PermissionError: [Errno 13] Permission denied: '/usr/share/brightness-controller/test'
/usr/bin/brightness-controller: line 4: 279170 Aborted                 (core dumped) python init.py

Desktop (please complete the following information):

  • OS: Manjaro Linux 5.16.14-1 64bit
  • Qt: 5.15.3
  • Version: brightness-controller-git (AUR) @ cd8cc61

Thanks for reporting. We will look into it.
I tried this in Ubuntu 20.04 (python3.8). There the program is unable to save anything on the root directory because it does not have permissions, but it does not crash afterward.

$ brightness-controller 
Qt: Session management error: networkIdsList argument is NULL
Traceback (most recent call last):
  File "/usr/share/brightness-controller/init.py", line 527, in save_settings
    WriteConfig.write_primary_display(
  File "/usr/share/brightness-controller/util/write_config.py", line 56, in write_primary_display
    with open(file_path, 'w+') as configfile:
PermissionError: [Errno 13] Permission denied: '/new.txt'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 153, in apport_excepthook
    with os.fdopen(os.open(pr_filename,
FileNotFoundError: [Errno 2] No such file or directory: '/var/crash/_usr_share_brightness-controller_init.py.1000.crash'

Original exception was:
Traceback (most recent call last):
  File "/usr/share/brightness-controller/init.py", line 527, in save_settings
    WriteConfig.write_primary_display(
  File "/usr/share/brightness-controller/util/write_config.py", line 56, in write_primary_display
    with open(file_path, 'w+') as configfile:
PermissionError: [Errno 13] Permission denied: '/new.txt'