src/geoipyupdate/__init__.py: try os.replace() before shutil.move()
It turns out that shutil.move() is not atomic, which can lead to
issues when replacing the database under heavy load. There is an
alternative in os.replace() that *is* atomic, but does not work across
filesystems. For the best of both worlds, we now try os.replace(), and
fall back to shutil.move() if it fails.
Testing shows that os.replace() raises an OSError across multiple
filesystems, so that's what we catch. The documentation doesn't
specify one way or the other.
Michael Orlitzky [Sun, 23 Mar 2025 13:28:16 +0000 (09:28 -0400)]
pyproject.toml: undo PEP639 license change
What an absolute circus. Although the documentation recommends them
and sdist warns about the old format, the new bare license strings
aren't actually supported by anything yet.
Michael Orlitzky [Sat, 22 Mar 2025 15:11:36 +0000 (11:11 -0400)]
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.