]> gitweb.michael.orlitzky.com - geoipyupdate.git/commit
src/geoipyupdate/__init__.py: try os.replace() before shutil.move()
authorMichael Orlitzky <michael@orlitzky.com>
Fri, 4 Apr 2025 01:45:39 +0000 (21:45 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Fri, 4 Apr 2025 01:45:39 +0000 (21:45 -0400)
commit8ed9904df585e46878f891c746c30bfa5c54fed0
tree241f66c59f9e572ef03683bba584739eb08382f8
parent8013e2a867a3bd7eb64d7affa692cee05b106e69
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.

Thanks to Paulo Magalhães for report.
src/geoipyupdate/__init__.py