Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve timestamps when extracting the squashfs #1216

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions ci/test-appimagetool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fi
log "check --mksquashfs-opt forwarding"
"$appimagetool" appimagetool.AppDir appimagetool.AppImage.1
"$appimagetool" appimagetool.AppDir appimagetool.AppImage.2 --mksquashfs-opt "-mem" --mksquashfs-opt "100M"
"$appimagetool" appimagetool.AppDir appimagetool.AppImage.3 --mksquashfs-opt "-all-time" --mksquashfs-opt "12345"
"$appimagetool" appimagetool.AppDir appimagetool.AppImage.3 --mksquashfs-opt "-all-time" --mksquashfs-opt "1234567890"
hash1=$(sha256sum appimagetool.AppImage.1 | awk '{print $1}')
hash2=$(sha256sum appimagetool.AppImage.2 | awk '{print $1}')
hash3=$(sha256sum appimagetool.AppImage.3 | awk '{print $1}')
Expand All @@ -134,6 +134,17 @@ if [ "$hash1" == "$hash3" ]; then
exit 1
fi

log "check mtimes are preserved when extracting squashfs"
./appimagetool.AppImage.3 --appimage-extract || echo "Can not extract AppImage on $(uname -m)"
if [ -d squashfs-root ]; then
ls -la squashfs-root
if [ "$(stat -c %Y squashfs-root/appimagetool.png)" != "1234567890" ]; then
echo "mtime of appimagetool.png is not 1234567890 / 2009-02-14 (as set by mksquashfs \"-all-time\"):"
exit 1
fi
fi
rm -rf squashfs-root

log "check appimagetool dies when mksquashfs fails"
set +e # temporarily disable error trapping as next line is supposed to fail
out=$("$appimagetool" appimagetool.AppDir appimagetool.AppImage --mksquashfs-opt "-misspelt-option" 2>&1)
Expand All @@ -142,4 +153,4 @@ set -e
test ${rc} == 1
echo "${out}" | grep -q "invalid option"
echo "${out}" | grep -qP 'mksquashfs \(pid \d+\) exited with code 1'
echo "${out}" | grep -q "sfs_mksquashfs error"
echo "${out}" | grep -q "sfs_mksquashfs error"
5 changes: 5 additions & 0 deletions src/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@ bool extract_appimage(const char* const appimage_path, const char* const _prefix
fwrite(buf, 1, bytes_at_a_time, f);
bytes_already_read = bytes_already_read + bytes_at_a_time;
}
fflush(f);
int fd = fileno(f);
struct timespec times[] = { st.st_atim, st.st_mtim };
if (futimens(fd, times) != 0)
fprintf(stderr, "futimens: %s\n", strerror(errno));
fclose(f);
chmod(prefixed_path_to_extract, st.st_mode);
if (!rv)
Expand Down