forked from importers/git-importer
Fix LFS register (it needs json not data)
Refactored the LFS Oid handling in its class of its own and add a way to recheck all LFS handles (or re-register)
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import hashlib
|
||||
import logging
|
||||
import os
|
||||
|
||||
try:
|
||||
import magic
|
||||
@@ -11,6 +10,7 @@ except:
|
||||
import requests
|
||||
|
||||
from lib.db import DB
|
||||
from lib.lfs_oid import LFSOid
|
||||
from lib.obs import OBS
|
||||
|
||||
|
||||
@@ -60,59 +60,9 @@ class ProxySHA256:
|
||||
if not mimetype:
|
||||
mimetype = self.mime.from_buffer(buffer)
|
||||
fin.close()
|
||||
sha = sha.hexdigest()
|
||||
with self.db.cursor() as cur:
|
||||
# we UPDATE here so the return functions. conflicts are likely as we look for filename/md5 but conflict on sha256
|
||||
cur.execute(
|
||||
"""INSERT INTO lfs_oids (project,package,filename,rev,sha256,size,mimetype,file_md5)
|
||||
VALUES (%s,%s,%s,%s,%s,%s,%s,%s)
|
||||
ON CONFLICT (sha256,size) DO UPDATE SET mimetype=EXCLUDED.mimetype
|
||||
RETURNING id""",
|
||||
(
|
||||
project,
|
||||
package,
|
||||
name,
|
||||
revision,
|
||||
sha,
|
||||
size,
|
||||
mimetype,
|
||||
file_md5,
|
||||
),
|
||||
)
|
||||
row = cur.fetchone()
|
||||
lfs_oid_id = row[0]
|
||||
cur.execute(
|
||||
"""INSERT INTO lfs_oid_in_package (package,filename,lfs_oid_id)
|
||||
VALUES (%s,%s,%s)""",
|
||||
(package, name, lfs_oid_id),
|
||||
)
|
||||
if mimetype.startswith("text/"):
|
||||
cur.execute(
|
||||
"INSERT INTO text_files (package,filename) VALUES (%s,%s)",
|
||||
(package, name),
|
||||
)
|
||||
self.db.conn.commit()
|
||||
|
||||
if os.getenv("GITEA_REGISTER_SECRET"):
|
||||
data = {
|
||||
"secret": os.getenv("GITEA_REGISTER_SECRET"),
|
||||
"project": project,
|
||||
"package": package,
|
||||
"filename": name,
|
||||
"rev": revision,
|
||||
"sha256": sha,
|
||||
"size": size,
|
||||
}
|
||||
|
||||
url = "http://gitea.opensuse.org:9999/register"
|
||||
response = requests.post(
|
||||
url,
|
||||
data=data,
|
||||
timeout=10,
|
||||
)
|
||||
logging.debug(f"Registered {response.status_code}")
|
||||
else:
|
||||
logging.info("Not registering LFS due to missing secret")
|
||||
LFSOid(self.db).add(
|
||||
project, package, name, revision, sha.hexdigest(), size, mimetype, file_md5
|
||||
)
|
||||
|
||||
# reset
|
||||
self.hashes = None
|
||||
|
Reference in New Issue
Block a user