openzim / zim-tools

Various ZIM command line tools
https://download.openzim.org/release/zim-tools/
GNU General Public License v3.0
123 stars 34 forks source link

test if symlink already created before to avoid unnecessary exception #416

Open nickhuang99 opened 3 months ago

nickhuang99 commented 3 months ago

In case zimdump run repeatedly, the symlink could be created already. So, before throwing exception, better to call "readLink" to check symlink.

nickhuang99 commented 3 months ago

I am not very sure about this "possible race condition" from CodeFactor (Possible race condition (CWE-362, CWE-20) (flawfinder7-readlink)). My guess is that this is only an improvement of one case when symlink already created. Say there is a race condition that a symlink is created after test is done so that we end up as the same exception. But this is NO WORSE than current code. So, I see no harm of this extra test to reduce some exception-throwing. It is NOT perfect solution, but just an improvement.