deptrac icon indicating copy to clipboard operation
deptrac copied to clipboard

Check if the file exists prior to checking if its writable

Open gnat42 opened this issue 3 years ago • 1 comments

When calling deptrac init if the file doesn't exist then isWritable is false and we error out. The SplFileInfo->isFile() "Checks if the file referenced by this SplFileInfo object exists and is a regular file." So if it exists and is a file but is not writeable then throw an error otherwise allow the file to be created and populated.

It would likely also be smart to add more error checking here. Such as checking if the dirname($target) exists and is writeable and if not try to create it or something.

gnat42 avatar Sep 09 '22 20:09 gnat42

Hey, thank you for your PR it was really valuable in understanding the problem.

I was curious, why the if condition before doesn't catch the existing file, so I started writing a test for the Dumper. I hope #987 solves your problem and prevents something similar from happening.

Feel free to copy my solution, so that I can merge your PR, if you would like to get the contribution credit. Otherwise I will just merge #987 instead.

dbrumann avatar Sep 22 '22 12:09 dbrumann

I'm happy for the fix to be in more than anything. You've got it all done so go ahead and merge your work!

gnat42 avatar Sep 22 '22 20:09 gnat42