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

fix for windows: refactored loadproperties function #128

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

LuigiVampa92
Copy link

What problem does it solve?

Function load properties in utils.kt is used to read .properties files and acquire values from there into Properties object. The current implementation opens file stream, get the data from it but does not manually close it.

This is completely not a problem in Unix-like operation systems (Linux, MacOS), however Windows uses approach with blocking file handles, which means that while the process that requested an access to the file hadn't close the handle manually, no other process can perform any modifying operations with the file. And since Mirakle plugin is used by the gradle daemon that runs in background, file got blocked and the only way to get access to it again is to manually kill the gradle daemon process. In case you would like to delete some previously opened properties file or write something to it you will constantly receive an exception, and even commands like "del /f file" that are used to force-delete files will be able to do anything with it.

The current implementation, again, does not face any of these problems because it does not write anything to properties files multiple times, however I've got a fork of Mirakle that relies on properties files and sometimes needs to delete or create a new one, check if any of previous ones exist and delete them in this case. And also it is just a more decent approach to work with files - releasing the stream objects after the work is done with them.

Solution

The fix that I provided in this pull request does its job and properties files will now work properly in any OS including Windows. I know it looks ugly as a smoking pile, with all this try-try-try-check-if-null approach from good old Java 6 times, but it is actually the only solution that worked in my test environment (I tested it on Windows 10). For some reason when I tried to simplify the code in Kotlin it still wasn't able to close the file handle on Windows, so I did it the boomer-way

…ased the stream object making a file forever occupied by gradle daemon process and thus inaccessible
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.

1 participant