unity-jar-resolver
unity-jar-resolver copied to clipboard
Fix project settings file getting corrupted
Why this change?
This resolve the settings file corruption as described in #524
Even though reading and writing of the settings file is protected by a lock, it is possible (due to domain reload) that 2 separate running processes are trying to access the file at the same time so the lock in one process is not aware of the other process.
A scenario like this could happen.
- Code in domain A will start writing to ProjectsSettings file
- Code in domain B will start reading the file
- If domain A didn't finish writing yet, domain B will encounter unexpected EOF
- Domain B will assume the file is broken and reset settings
- Domain B will write default settings to ProjectsSettings file
What did I do?
I made the writing happen to a temporary file. When the writing is complete, copy the temp file to the target path. This avoids the file being in an "invalid state" for a short time during the writing.
Review
Feedback is greatly appreciated and please let me know which steps I need to take to make my change release-ready.