Closed simonw closed 6 months ago
I got Claude 3 Opus to write the first version: https://gist.github.com/simonw/4cecde4a729f4da0b5059b50c8e01359
For checking space:
import shutil
# Get the total, used, and free space in bytes for the /tmp directory
total, used, free = shutil.disk_usage('/tmp')
The free
will be in bytes.
Still needed:
/tmp
necessary space before executingI'm going to test for available space when the user requests a download, not every time I show the export button. I don't think it's worth the extra computation on every page load for a button that is hardly ever pressed. It would also be confusing to the user if the button sometimes isn't there.
One thing that bothers me here is that /db/-/export-database
is an expensive operation - and someone malicious could trick logged in users into triggering it by sending them links to that full URL.
Since database actions cannot perform POST requests just yet I'm going to add a signed parameter to the URL instead, to ensure users cannot have export links generated for them.
Goal is a datbase action menu item that can request a SQLite database copy. If there is enough space in
/tmp
it runs a subprocess that does aVACUUM INTO
to create an atomic snapshot in a temporary file, then lets you download it, then deletes the file.