]> gitweb.michael.orlitzky.com - geoipyupdate.git/commit
src/geoipyupdate/__init__.py: respect umask for the database
authorMichael Orlitzky <michael@orlitzky.com>
Sat, 22 Mar 2025 15:11:36 +0000 (11:11 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Sat, 22 Mar 2025 15:18:29 +0000 (11:18 -0400)
commit7559ed92f9e0f3f75a80d8f5d2b4cadba1a319eb
treebdd99f5ac1464ff2bec717ffe67516707d94bbd8
parentbc5e2f73d50d0e0d0689265cba91562f6d6bced8
src/geoipyupdate/__init__.py: respect umask for the database

All python temporary files are created with mode 600, and that
includes the temporary files that we use to download/decompress the
database. When we eventually move the database to its destination, it
retains these permissions and needs to be chmod'ed. This leads to a
race condition where web applications can raise permission errors in
the instant that the database is unreadable.

The solution to this is obvious, we should just respect the umask.
But python makes this very hard to do: the tempfile module ignores the
umask, and you can't obtain the umask without changing it, and
changing it affects other threads... anyway, it can be done, if
carefully. This commit uses os.chmod() on the database file to make it
world readable and group writable, minus whatever permissions the user
has masked.
src/geoipyupdate/__init__.py