Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileNotFoundError when displaying the settings page #7473

Closed
kozlovsky opened this issue Jun 11, 2023 · 0 comments
Closed

FileNotFoundError when displaying the settings page #7473

kozlovsky opened this issue Jun 11, 2023 · 0 comments
Assignees
Milestone

Comments

@kozlovsky
Copy link
Collaborator

The issue was caught by the Application Tester:

Traceback (most recent call last):
  File "tribler\gui\utilities.py", line 438, in trackback_wrapper
  File "tribler\gui\utilities.py", line 435, in trackback_wrapper
  File "tribler\gui\widgets\settingspage.py", line 230, in initialize_with_settings
  File "tribler\gui\widgets\settingspage.py", line 256, in load_settings_data_tab
  File "tribler\gui\widgets\settingspage.py", line 261, in refresh_current_version_checkbox
  File "tribler\gui\widgets\settingspage.py", line 275, in refresh_version_checkboxes
  File "tribler\gui\widgets\settingspage.py", line 250, in _version_dir_checkbox
  File "tribler\core\utilities\path_util.py", line 59, in size
  File "tribler\core\utilities\path_util.py", line 59, in <genexpr>
  File "genericpath.py", line 50, in getsize
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\Users\\tribler\\AppData\\Roaming\\.Tribler\\7.13\\sqlite\\knowledge.db-journal'

It looks like we have a raise condition in Path.size():

    def size(self, include_dir_sizes: bool = True) -> int:
        """ Return the size of this file or directory (recursively).

        Args:
            include_dir_sizes: If True, return the size of files and directories, not the size of files only.

        Returns: The size of this file or directory.
        """
        if not self.exists():
            return 0

        if self.is_file():
            return self.stat().st_size

        size = os.path.getsize(self.absolute()) if include_dir_sizes else 0  # get root dir size
        for root, dir_names, file_names in os.walk(self):
            names = itertools.chain(dir_names, file_names) if include_dir_sizes else file_names
            paths = (os.path.join(root, name) for name in names)
            size += sum(os.path.getsize(p) for p in paths if os.path.exists(p))  # <-- the error is happened here
        return size

The function checks that the file exists and immediately asks for its size. But it may be possible that the file was deleted right after the exists call. To handle this, we need to add a try/except block that catches FileNotFoundError.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant