Editing PHP-generated log file in PhpStorm creates new file appended with tilde, makes original file uneditable
I've used a log script for years across different projects to debug (when I can't use normal, better things), which writes debug info to a `[whatever].log` file, but on my latest project, I'm getting an odd error whenever I modify any of the log files (they're just temporary, don't worry).
For instance, I write an array of more than 10 elements to JSON text, then if it's too hard to read, I copy-paste the JSON to a `tmp.json` file, format it to be readable, then I may paste it back into the log file for reference.
However, whenever I modify the log file on this project, PhpStorm pops up a little box saying “Cannot save [whatever].log. Unable to open the file for writing.”
When I look at the file in Explorer (Windows Server 2022), I notice a duplicate file with ~ appended… When I check the original file's permissions, it has all permissions allowed for SYSTEM and Administrators, and read & execute for Users.
When I look at the ~ file, it matches the original's permissions but then also has my username added but with full permissions.
When I look at any other file already in the repo (since cloning), they have the same permissions as the ~ file…
So, when PHP creates the log file, it creates it without my username in the permissions. I suppose this makes sense, since Apache's creating it (with whatever user it uses), but then I don't have access to modify the file. Strangely, the file still shows modified in PhpStorm's file tab, but I don't view it anywhere else anyway, so maybe I don't need to care if it's actually saved to a log file I'm gonna delete soon anyway.
So… any workaround to stop getting this error pop-up? It's distracting, and an extra step that I sometimes forget about until it's too late.
Please sign in to leave a comment.
Please note that it's not the case here - editing the file in PhpStorm doesn't make it uneditable; it's already uneditable before you edit it in PhpStorm.
There are two possible solutions: