Skip to content

Fix saving when the cache workspace path is a file - #555

Open
shreyanshj10 wants to merge 1 commit into
vikdevelop:mainfrom
shreyanshj10:fix/issue-554-cleanup-cache-dir
Open

shreyanshj10 wants to merge 1 commit into
vikdevelop:mainfrom
shreyanshj10:fix/issue-554-cleanup-cache-dir

Conversation

@shreyanshj10

Copy link
Copy Markdown

Pull request

Description

Saving fails permanently with NotADirectoryError: [Errno 20] Not a directory: .../cache/tmp/workspace when the workspace path in the cache directory happens to be a file instead of a directory. cleanup_cache_dir() only catches FileNotFoundError, so shutil.rmtree() raises and every save attempt ends in "An error occurred" until the user deletes that file by hand.

Two changes:

  • cleanup_cache_dir() now removes the workspace path with os.remove() when it is a file or a symlink, and keeps using shutil.rmtree() otherwise. The app recovers on its own instead of staying broken.
  • create_flatpak_autostart() creates the workspace directory before the cp. This is where the stray file comes from: cp <file> {CACHE}/workspace creates workspace as a file when the directory is not there, and the next create_flatpak_autostart() call would fail on the flatpak-prefs.json write anyway.

Related Issue

Changes Made

  • Fixed bug: Describe the bug and how it was fixed.

Screenshots (if applicable)

Not applicable, no visual changes.

Testing

  • I have tested my changes via GNOME Builder

I exercised cleanup_cache_dir() directly against three states of the workspace path - missing, an existing directory with content in it, and a plain file - and confirmed that it raises on the third one before the change and leaves an empty directory behind in all three after it.

Checklist

  • I have read the contributing guidelines.
  • I have performed a self-review of my code.
  • I have commented my code where necessary.
  • My changes do not introduce any new warnings.

Additional Notes

remove_cache() in gui/window.py and cache_cleanup() in gui/flatpaks_installer_window.py call shutil.rmtree() on the same path behind an os.path.exists() check, so they would hit the same error on a cache that is already in this state. I left them alone to keep this focused on the save path from the issue, but happy to include them if you would like.

@shreyanshj10
shreyanshj10 marked this pull request as ready for review October 1, 2026 09:12

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Can't Save: "An error occurred"

1 participant