Skip to content

The checksum adding step uses a temp file name too#1107

Closed
veloman-yunkan wants to merge 1 commit into
mainfrom
zimfile.zim.without_checksum
Closed

The checksum adding step uses a temp file name too#1107
veloman-yunkan wants to merge 1 commit into
mainfrom
zimfile.zim.without_checksum

Conversation

@veloman-yunkan

@veloman-yunkan veloman-yunkan commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1106

Now ZIM creation uses a temporary file name during the checksum computation stage too.

Before checksum computation starts the name of the temporary file is REQURESTED_OUTPUT_FILE_NAME.tmp (this file is auto-deleted if an unrecoverable exception is thrown during ZIM writing). This is old behaviour and is mentioned merely for completeness.

During checksum computation the temporary file is renamed to REQURESTED_OUTPUT_FILE_NAME.without_checksum, which is renamed to the final name REQURESTED_OUTPUT_FILE_NAME after the checksum is added (resulting in a valid ZIM file).

If checksum computation fails for whatever reason the *.without_checksum file is preserved and can be converted to a valid ZIM file by a simple script such as below (note that it doesn't rename the input file, which must be done separately):

#!/usr/bin/env bash

compute_zim_checksum()
{
    local zimfilepath=$1
    local n=$(cat "$zimfilepath"|wc -c)
    head -c $n "$zimfilepath"|md5sum|cut -d' ' -f 1
}

overwrite_bytes_in_file()
{
  local fname=$1
  local bytes=$2
  local offset=$3
  local nbytes=$(printf "$bytes"|wc -c)
  printf "$bytes" |
    dd of="$fname" bs=1 seek=$offset count=$nbytes conv=notrunc &> /dev/null
}

set_zimfile_checksum()
{
    local zimfilepath=$1
    local checksum_str=$2
    local n=$(cat "$zimfilepath"|wc -c)
    checksum_str=$(sed 's/\(..\)/\\x\1/g'<<<"$checksum_str")
    overwrite_bytes_in_file "$zimfilepath" "$checksum_str" $n
}

checksum_hexstr=$(compute_zim_checksum "$1")
echo "Setting checksum of file '$1' to $checksum_hexstr"
set_zimfile_checksum "$1" "$checksum_hexstr"

@veloman-yunkan
veloman-yunkan requested a review from kelson42 July 9, 2026 12:24
@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.02%. Comparing base (d3f2313) to head (2078f70).

Files with missing lines Patch % Lines
src/writer/creator.cpp 0.00% 0 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1107      +/-   ##
==========================================
- Coverage   56.39%   56.02%   -0.37%     
==========================================
  Files         100      100              
  Lines        5050     5053       +3     
  Branches     2241     2263      +22     
==========================================
- Hits         2848     2831      -17     
  Misses        728      728              
- Partials     1474     1494      +20     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kelson42 kelson42 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@veloman-yunkan Please keep older behaviour. keep the old temporary name, don't introduce any new file extension. Just secure that when it is called .zim, then this is a ZIM.

@veloman-yunkan

Copy link
Copy Markdown
Collaborator Author

@veloman-yunkan Please keep older behaviour. keep the old temporary name, don't introduce any new file extension.

@kelson42 I don't understand why you care so much about the name of the temporary file that in most situations will play no role (but will help to figure out what was wrong if things go wrong).

Just secure that when it is called .zim, then this is a ZIM.

That's the case with this PR.

@veloman-yunkan veloman-yunkan changed the title The checksum adding step uses a temp file too The checksum adding step uses a temp file name too Jul 11, 2026
@kelson42

Copy link
Copy Markdown
Contributor

@veloman-yunkan Please keep older behaviour. keep the old temporary name, don't introduce any new file extension.

@kelson42 I don't understand why you care so much about the name of the temporary file that in most situations will play no role (but will help to figure out what was wrong if things go wrong).

No, everybody writing ZIM file will see that. Uselessly complicated and potentially creating side effects.

@kelson42

Copy link
Copy Markdown
Contributor

Superseeded by #1108

@kelson42 kelson42 closed this Jul 11, 2026
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.

Do not create .zim file until ZIM file is fully ready

2 participants