mirror of
https://github.com/tuna/tunasync-scripts.git
synced 2025-06-30 23:12:45 +00:00
fix bugs in size calculation
This commit is contained in:
parent
c71008f008
commit
b1ae8488ac
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
# requires: coreutils
|
||||
[[ -f "$1" ]] || exit
|
||||
[[ -f "$1" ]] || exit 0
|
||||
sz=$(cat $1)
|
||||
sz=$((0$sz))
|
||||
echo "size-sum:" $(numfmt --to=iec $sz)
|
||||
|
20
yum-sync.py
20
yum-sync.py
@ -21,21 +21,23 @@ REPO_STAT = {}
|
||||
def calc_repo_size(path: Path):
|
||||
dbfiles = path.glob('repodata/*primary.sqlite*')
|
||||
with tempfile.NamedTemporaryFile() as tmp:
|
||||
dec = None
|
||||
dbfile = None
|
||||
for db in dbfiles:
|
||||
with db.open('rb') as f:
|
||||
dbfile = db
|
||||
suffix = db.suffix
|
||||
if suffix == '.bz2':
|
||||
tmp.write(bz2.decompress(f.read()))
|
||||
break
|
||||
dec = bz2.decompress
|
||||
elif suffix == '.gz':
|
||||
tmp.write(gzip.decompress(f.read()))
|
||||
break
|
||||
elif suffix == '':
|
||||
tmp.write(f.read())
|
||||
break
|
||||
else:
|
||||
dec = gzip.decompress
|
||||
elif suffix == '.sqlite':
|
||||
dec = lambda x: x
|
||||
if dec is None:
|
||||
print(f"Failed to read DB from {path}: {dbfiles}", flush=True)
|
||||
return
|
||||
with db.open('rb') as f:
|
||||
tmp.write(dec(f.read()))
|
||||
tmp.flush()
|
||||
|
||||
conn = sqlite3.connect(tmp.name)
|
||||
c = conn.cursor()
|
||||
|
Loading…
x
Reference in New Issue
Block a user