Skip to content

Fix data loss in rmtree when deletion fails#45

Merged
jovnc merged 5 commits intogit-mastery:mainfrom
desmondwong1215:fix/rmtree
Mar 16, 2026
Merged

Fix data loss in rmtree when deletion fails#45
jovnc merged 5 commits intogit-mastery:mainfrom
desmondwong1215:fix/rmtree

Conversation

@desmondwong1215
Copy link
Contributor

Fixes NUS-CS2103-AY2526-S2/forum#82

When rmtree() fails (e.g., folder locked by another process), shutil.rmtree partially deletes files before raising an exception. This causes permanent data loss - users lose their progress.json despite the operation failing. It also applies to other parts in the app that use rmtree.

Solution:
Implement backup-and-restore mechanism in rmtree()):

  1. Create a hidden backup before deletion
  2. Attempt deletion
    2a. If deletion fails: restore from backup automatically
    2b. If restoration also fails: preserve the backup and show the user the path; the user can manually update the path before retrying.

@jovnc jovnc merged commit 532c0c4 into git-mastery:main Mar 16, 2026
0 of 3 checks passed
@desmondwong1215 desmondwong1215 deleted the fix/rmtree branch March 16, 2026 06:57
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.

[Gitmastery] Local progress also deleted when running gitmastery progress sync on or off while accessing progress folder from another terminal

2 participants