Skip to content

Remove stale partial downloads of older ZIM versions / Eski sürümlerin yarım indirmelerini sil - #30

Open
menes97 wants to merge 2 commits into
schematrix:mainfrom
menes97:fix/stale-part-files
Open

menes97 wants to merge 2 commits into
schematrix:mainfrom
menes97:fix/stale-part-files

Conversation

@menes97

@menes97 menes97 commented Nov 10, 2026

Copy link
Copy Markdown

English · Türkçe

English

Two small fixes in scripts/download-content.sh, one commit each.

1. Unfinished downloads of older versions are removed
Say the English Wikipedia download (wikipedia_en_all_maxi_2026-10.zim.part, ~120 GB) is interrupted, and by the next run the catalog has 2026-11. The script starts 2026-11 from scratch, but the 2026-10.zim.part stays on the disk forever:

  • It is never resumed, because the script only resumes the newest version.
  • The old-version cleanup after a download only matches *.zim, not *.zim.part.
  • It takes up its space, so the free-space check for the new version can fail with "not enough space".
  • status.sh keeps reporting "unfinished download(s)".

With the approval-based updates in #14, this would happen every time a big ZIM gets a new release while it is downloading.

Now, after the newest version is resolved and before the free-space check, .part files of other versions of the same prefix are removed. The .part of the current version is kept and resumed as before. The glob is the same one as the old-version cleanup (<prefix>_YYYY-MM…), so wikipedia_en_all does not touch wikipedia_en_all_maxi files.

2. The catalog temp file is removed when the catalog is unreachable
The EXIT trap removes "$CAT", but the fallback path sets CAT="" first, so the mktemp file was left in /tmp. It is now removed before the variable is cleared.

Testing

I don't have a Pi, so I ran the script as root in Ubuntu 24.04 (WSL), with curl and wget replaced by stubs (a fake catalog, a fake directory listing, a 5-byte "ZIM" and its .sha256). Each case was run against this branch and against main:

Case main this PR
Stale 2026-10.zim.part, catalog has 2026-11: stale part removed ❌ ✅
Same: 2026-11 downloaded and verified ✅ ✅
.part of a longer prefix (foo_en_all_maxi_…) left alone ✅ ✅
.part of the current version is resumed, nothing removed ✅ ✅
Newest version already present: stale part still removed ❌ ✅
Catalog unreachable: no temp file left in TMPDIR ❌ ✅
Catalog unreachable: directory-listing fallback still downloads ✅ ✅
Catalog unreachable: stale part removed ❌ ✅

I couldn't run ShellCheck locally; the new loop follows the same pattern as the existing old-version cleanup loop, and the ShellCheck workflow will check it here. #14 also edits this file, but in other lines; if this lands first, CHECK_ONLY=1 would remove stale .part files too. That seems right, since they can't be resumed, but I'm happy to move the cleanup below the CHECK_ONLY line if you prefer.

Türkçe

scripts/download-content.sh içinde iki küçük düzeltme, her biri ayrı commit.

1. Eski sürümlerin yarım indirmeleri siliniyor
Diyelim ki İngilizce Vikipedi indirmesi (wikipedia_en_all_maxi_2026-10.zim.part, ~120 GB) yarıda kaldı ve bir sonraki çalıştırmada katalogda 2026-11 var. Betik 2026-11'i baştan indiriyor ama 2026-10.zim.part diskte kalıyor:

  • Betik yalnızca en yeni sürüme devam ettiği için bu dosyaya hiç devam edilmiyor.
  • İndirme sonrası eski sürüm temizliği yalnızca *.zim dosyalarına bakıyor, *.zim.part dosyalarına bakmıyor.
  • Dosya yerini koruyor; yeni sürümün yer kontrolü "yer yok" diyerek durabiliyor.
  • status.sh sürekli "yarım indirme" uyarısı veriyor.

#14'teki onaylı güncellemelerle bu durum, büyük bir ZIM indirilirken yeni sürümü her çıktığında yaşanır.

Artık en yeni sürüm bulunduktan sonra ve yer kontrolünden önce, aynı adın diğer sürümlerine ait .part dosyaları siliniyor. Güncel sürümün .part dosyası eskisi gibi korunuyor ve devam ediliyor. Glob, eski sürüm temizliğindekiyle aynı (<ad>_YYYY-MM…); yani wikipedia_en_all, wikipedia_en_all_maxi dosyalarına dokunmuyor.

2. Katalog alınamazsa geçici dosya siliniyor
EXIT trap'i "$CAT"i siliyor, ama klasör listesine düşülürken önce CAT="" yapıldığı için mktemp dosyası /tmp'de kalıyordu. Artık değişken boşaltılmadan önce dosya siliniyor.

Test

Elimde Pi olmadığı için betiği Ubuntu 24.04'te (WSL) root olarak çalıştırdım; curl ve wget yerine sahte bir katalog, sahte bir klasör listesi, 5 baytlık bir "ZIM" ve .sha256 dosyası veren betikler koydum. Her durumu hem bu dalda hem main'de çalıştırdım; sonuçlar yukarıdaki tabloda. main'de yalnızca bu PR'ın düzelttiği dört durum başarısız oluyor.

ShellCheck'i yerelde çalıştıramadım; yeni döngü mevcut eski sürüm temizliği döngüsüyle aynı kalıpta ve buradaki ShellCheck iş akışı kontrol edecek. #14 de bu dosyayı değiştiriyor ama başka satırlarda. Bu PR önce birleşirse CHECK_ONLY=1 de eski .part dosyalarını siler; devam edilemeyecekleri için bu bana doğru geliyor, ama isterseniz temizliği CHECK_ONLY satırının altına alabilirim.

AI assistance / YZ desteği: The change, the tests and this description were written with Claude Code and checked with the runs above. / Değişiklik, testler ve bu açıklama Claude Code ile yazıldı ve yukarıdaki çalıştırmalarla kontrol edildi.

🤖 Generated with Claude Code

menes97 and others added 2 commits November 10, 2026 14:01
…arım indirmelerini sil

When a download is interrupted and a newer version of the same ZIM is out by the next run, the
old <prefix>_YYYY-MM.zim.part is never resumed and never removed: the old-version cleanup only
matches *.zim. It keeps its space (up to ~120 GB for English Wikipedia), counts as used in the
free-space check, and status.sh reports an unfinished download forever. Remove partial files of
other versions of the same prefix before the free-space check.

Bir indirme yarıda kalır ve sonraki çalıştırmada aynı ZIM'in yeni sürümü çıkmışsa eski
<prefix>_YYYY-MM.zim.part dosyasına ne devam edilir ne de silinir: eski sürüm temizliği yalnızca
*.zim dosyalarına bakar. Dosya yerini korur (İngilizce Vikipedi için ~120 GB'a kadar), yer
kontrolünde dolu sayılır ve status.sh sürekli yarım indirme uyarısı verir. Aynı adın diğer
sürümlerinin yarım dosyaları yer kontrolünden önce silinir.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g alınamazsa geçici dosyayı sil

The EXIT trap removes "$CAT", but the fallback path clears CAT first, so the mktemp file was left
in /tmp. Remove it before clearing the variable.

EXIT trap'i "$CAT"i siler, ama klasör listesine düşülürken CAT önce boşaltıldığı için mktemp
dosyası /tmp'de kalıyordu. Değişken boşaltılmadan önce dosya silinir.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant