diff options
Diffstat (limited to 'paste/store.py')
-rw-r--r-- | paste/store.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/paste/store.py b/paste/store.py index 26643cf..82e66c0 100644 --- a/paste/store.py +++ b/paste/store.py @@ -7,17 +7,22 @@ def put(conn: Connection, name: str, content: bytes, content_type: str): "INSERT OR IGNORE INTO file (content) VALUES (?)", (content,), ) + (content_hash,) = conn.execute("SELECT DATA_HASH(?)", (content,)).fetchone() + cur = conn.execute( + """UPDATE link + SET content_type = ?, file_hash = ? + WHERE name_hash = DATA_HASH(?)""", + (content_type, content_hash, name), + ) + if cur.rowcount == 1: + return False, content_hash conn.execute( - """ - INSERT INTO link ( + """INSERT INTO link ( name, content_type, file_hash - ) VALUES (?, ?, DATA_HASH(?)) - ON CONFLICT DO UPDATE - SET - content_type = excluded.content_type, - file_hash = excluded.file_hash""", - (name, content_type, content), + ) VALUES (?, ?, ?)""", + (name, content_type, content_hash), ) + return True, content_hash def get(conn: Connection, name: str): |