[tbb-commits] [Git][tpo/applications/tor-browser-build][main] Bug 40847: Do not rely on du to compute the HFS size

Pier Angelo Vendrame (@pierov) git at gitlab.torproject.org
Wed Jun 7 16:31:28 UTC 2023



Pier Angelo Vendrame pushed to branch main at The Tor Project / Applications / tor-browser-build


Commits:
2579da7c by Pier Angelo Vendrame at 2023-06-07T18:30:37+02:00
Bug 40847: Do not rely on du to compute the HFS size

HFS has the disadvantage that we cannot grow the filesystem while
adding files.
We have to estimate an initial size, instead, and we relied on du for
this. However, du depends on the underlying filesystem, and this could
lead to reproducibility issues (because the HFS headers tell different
sizes).

So, with this change, we compute a rough number of needed blocks by
taking the actual size of the files.

Overshooting is not a problem, because DMG is compressed with bzip2, so
unused space will be trimmed, eventually.

- - - - -


2 changed files:

- projects/browser/ddmg.sh
- tools/signing/ddmg.sh


Changes:

=====================================
projects/browser/ddmg.sh
=====================================
@@ -14,9 +14,13 @@ hfsfile="\$dmg_tmpdir/tbb-uncompressed.dmg"
 export LD_PRELOAD=[% c("var/faketime_path") %]
 export FAKETIME="[% USE date; GET date.format(c('timestamp'), format = '%Y-%m-%d %H:%M:%S') %]"
 
-# Use a similar strategy to Mozilla (they have 1.02, we have 1.1)
-size=\$(du -ms [% src %] | awk '{ print int( \$1 * 1.1 ) }')
-dd if=/dev/zero of="\$hfsfile" bs=1M count=\$size
+src_dir=[% src %]
+# 1 for ceiling and 1 for the inode
+fileblocks=\$(find "\$src_dir" -type f -printf '%s\n' | awk '{s += int(\$1 / 4096) + 2} END {print s}')
+directories=\$(find "\$src_dir" -type d | wc -l)
+# Give some room to breathe
+size=\$(echo \$((\$fileblocks + \$directories)) | awk '{print int(\$1 * 1.1)}')
+dd if=/dev/zero of="\$hfsfile" bs=4096 count=\$size
 newfs_hfs -v "[% c("var/Project_Name") %]" "\$hfsfile"
 
 pushd [% src %]


=====================================
tools/signing/ddmg.sh
=====================================
@@ -30,9 +30,12 @@ export FAKETIME="2000-01-01 01:01:01"
 
 echo "Starting: " $(basename $dest_file)
 
-# Use a similar strategy to Mozilla (they have 1.02, we have 1.1)
-size=$(du -ms "$src_dir" | awk '{ print int( $1 * 1.1 ) }')
-dd if=/dev/zero of="$hfsfile" bs=1M count=$size
+# 1 for ceiling and 1 for the inode
+fileblocks=$(find "$src_dir" -type f -printf '%s\n' | awk '{s += int($1 / 4096) + 2} END {print s}')
+directories=$(find "$src_dir" -type d | wc -l)
+# Give some room to breathe
+size=$(echo $(($fileblocks + $directories)) | awk '{print int($1 * 1.1)}')
+dd if=/dev/zero of="$hfsfile" bs=4096 count=$size
 newfs_hfs -v "$volume_label" "$hfsfile"
 
 cd $src_dir



View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser-build/-/commit/2579da7c8f23ce4d0cfb7da6de5a86e9404b265a

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser-build/-/commit/2579da7c8f23ce4d0cfb7da6de5a86e9404b265a
You're receiving this email because of your account on gitlab.torproject.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tbb-commits/attachments/20230607/5511138f/attachment-0001.htm>


More information about the tbb-commits mailing list