Skip to content

Timestamp support - #187

Open
TheComputerGuy96 wants to merge 9 commits into
twogood:mainfrom
TheComputerGuy96:timestamp-support
Open

TheComputerGuy96 wants to merge 9 commits into
twogood:mainfrom
TheComputerGuy96:timestamp-support

Conversation

@TheComputerGuy96

Copy link
Copy Markdown

Fixes #100

The timestamp setting code currently doesn't use the file wrappers though (and is directly located in unshield.c)

@twogood

twogood commented Dec 14, 2024

Copy link
Copy Markdown
Owner

Very nice! What work is need to support it in the wrapper?

@twogood twogood self-assigned this Dec 14, 2024
@TheComputerGuy96

Copy link
Copy Markdown
Author

What work is need to support it in the wrapper?

I think it's as easy as adding the relevant callbacks (but I'm not sure if those 2 functions have alternative implementations; especially the utime() function)

These were originally present in the early unshield code but
for some reason they were removed later (this change is based
on the i5comp and i6comp struct layout)

Those struct members have a correct date with the Baldur's Gate
test (likely <IS6?) and GTA San Andreas (IS9)
@TheComputerGuy96
TheComputerGuy96 force-pushed the timestamp-support branch 2 times, most recently from 5a67093 to b3c5979 Compare January 9, 2026 14:57
@TheComputerGuy96

Copy link
Copy Markdown
Author

After looking some more, I noticed the unshield binary uses direct stat() calls (so function wrappers may not be needed there)

Also while the timestamp setting code could be moved to another function or as a part of common extract code, I don't think it's that important

@twogood

twogood commented Jan 9, 2026

Copy link
Copy Markdown
Owner

After looking some more, I noticed the unshield binary uses direct stat() calls (so function wrappers may not be needed there)

Also while the timestamp setting code could be moved to another function or as a part of common extract code, I don't think it's that important

I thought of including it in function wrappers for consistency.

Copilot AI 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.

Pull request overview

This pull request adds timestamp support to the unshield tool, allowing users to preserve the original modification date/time from InstallShield metadata when extracting files. This addresses issue #100.

Key Changes:

  • Adds a new -t command-line flag to enable timestamp preservation during extraction
  • Implements DOS timestamp parsing and conversion to Unix time_t
  • Updates file listing to display timestamps in ISO 8601 format

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/unshield.c Adds -t option handling, timestamp setting logic in extract_file(), and date display in file listing
man/unshield.1 Documents the new -t option and updates man page date to December 2024
lib/libunshield.h Declares two new public API functions: unshield_file_iso_date() and unshield_file_timestamp()
lib/internal.h Declares internal helper function unshield_dos_to_tm() for DOS timestamp conversion
lib/helper.c Implements unshield_dos_to_tm() to convert DOS date/time format to struct tm
lib/file.c Implements the new API functions and adds DOS date/time parsing in file descriptor reading
lib/cabfile.h Adds dos_date and dos_time fields to FileDescriptor structure

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread man/unshield.1 Resolved
Comment thread src/unshield.c Resolved
Comment thread lib/helper.c Resolved
Comment thread src/unshield.c Resolved
Comment thread lib/file.c Resolved
@twogood

twogood commented Jan 11, 2026

Copy link
Copy Markdown
Owner

@TheComputerGuy96 not meaning to give you extra work but do you think the Copilot comments have any merit? It could also be possible to merge this PR and address those comments in a second PR.

TheComputerGuy96 and others added 2 commits January 14, 2026 12:07
This also adds a helper function to load the DOS date/time into a tm
structure and an library function to get the ISO 8601 date

Co-authored-by: GitHub Copilot <copilot@github.com>
This also adds an API function for getting an Unix timestamp
(and updates the man page)

Co-authored-by: GitHub Copilot <copilot@github.com>
@TheComputerGuy96

Copy link
Copy Markdown
Author

do you think the Copilot comments have any merit?

@twogood I added extra safety checks in the new PR version (which should mostly appease Copilot)

Copilot AI 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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/file.c
Comment on lines +70 to +72
fd->dos_date = (uint16_t)READ_UINT32(p); p += 4;
fd->dos_time = (uint16_t)READ_UINT32(p); p += 4;
p += 8;

Copilot AI Jan 21, 2026

Copy link

Choose a reason for hiding this comment

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

The code reads dos_date and dos_time as 32-bit values using READ_UINT32 and then casts them to 16-bit. This seems inconsistent with the later versions (6+) which read them as 16-bit values directly. If the file format actually stores these as 32-bit values in versions 0 and 5, consider documenting why this is the case. If they are actually 16-bit fields, use READ_UINT16 instead and adjust the pointer increment accordingly. The current approach may work but could be confusing and potentially read incorrect data depending on endianness and padding.

Copilot uses AI. Check for mistakes.
Comment thread src/unshield.c Outdated
dirname = malloc(path_max);
filename = malloc(path_max);
full_filename = malloc(path_max);
if (real_output_directory == NULL || real_filename == NULL)

Copilot AI Jan 21, 2026

Copy link

Choose a reason for hiding this comment

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

The NULL check only verifies real_output_directory and real_filename, but doesn't check the newly allocated dirname and full_filename pointers. If malloc fails for these variables, they will be NULL and dereferencing them later will cause a segmentation fault. The NULL check should include dirname and full_filename as well.

Suggested change
if (real_output_directory == NULL || real_filename == NULL)
if (real_output_directory == NULL || real_filename == NULL ||
dirname == NULL || full_filename == NULL)

Copilot uses AI. Check for mistakes.
Comment thread src/unshield.c
Comment on lines +561 to +577
fprintf(stderr, "Failed to get timestamp for file '%s'.", filename);
}
else
{
memset(&utim, 0, sizeof(utim));
memset(&info, 0, sizeof(info));

ret = stat(full_filename, &info);
if (ret == 0)
{
utim.actime = info.st_atime;
utim.modtime = timestamp;
ret2 = utime(full_filename, &utim);
}

if (ret < 0 || ret2 < 0)
fprintf(stderr, "Failed to set timestamp for file '%s'.", filename);

Copilot AI Jan 21, 2026

Copy link

Choose a reason for hiding this comment

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

The error messages on lines 561 and 577 are missing a newline character at the end, which is inconsistent with other error messages in this file and can make the output harder to read. Add '\n' at the end of both error messages.

Copilot uses AI. Check for mistakes.
Comment thread src/unshield.c Outdated
Comment on lines +559 to +578
if (!timestamp)
{
fprintf(stderr, "Failed to get timestamp for file '%s'.", filename);
}
else
{
memset(&utim, 0, sizeof(utim));
memset(&info, 0, sizeof(info));

ret = stat(full_filename, &info);
if (ret == 0)
{
utim.actime = info.st_atime;
utim.modtime = timestamp;
ret2 = utime(full_filename, &utim);
}

if (ret < 0 || ret2 < 0)
fprintf(stderr, "Failed to set timestamp for file '%s'.", filename);
}

Copilot AI Jan 21, 2026

Copy link

Choose a reason for hiding this comment

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

The check for a zero timestamp may not be appropriate here. A timestamp of 0 (Unix epoch: January 1, 1970) is a valid timestamp value, though unlikely for InstallShield files. The code should distinguish between a valid timestamp of 0 and an error condition. Consider checking if unshield_file_timestamp returned 0 due to an error versus having an actual 0 timestamp (which would be a valid DOS date/time of 00:00:00 on an invalid date). The current implementation will skip setting timestamps for files that legitimately have a timestamp of 0.

Suggested change
if (!timestamp)
{
fprintf(stderr, "Failed to get timestamp for file '%s'.", filename);
}
else
{
memset(&utim, 0, sizeof(utim));
memset(&info, 0, sizeof(info));
ret = stat(full_filename, &info);
if (ret == 0)
{
utim.actime = info.st_atime;
utim.modtime = timestamp;
ret2 = utime(full_filename, &utim);
}
if (ret < 0 || ret2 < 0)
fprintf(stderr, "Failed to set timestamp for file '%s'.", filename);
}
memset(&utim, 0, sizeof(utim));
memset(&info, 0, sizeof(info));
ret = stat(full_filename, &info);
if (ret == 0)
{
utim.actime = info.st_atime;
utim.modtime = timestamp;
ret2 = utime(full_filename, &utim);
}
if (ret < 0 || ret2 < 0)
fprintf(stderr, "Failed to set timestamp for file '%s'.", filename);

Copilot uses AI. Check for mistakes.
Comment thread src/unshield.c
Comment on lines +556 to +573
struct utimbuf utim;
struct stat info;

if (!timestamp)
{
fprintf(stderr, "Failed to get timestamp for file '%s'.", filename);
}
else
{
memset(&utim, 0, sizeof(utim));
memset(&info, 0, sizeof(info));

ret = stat(full_filename, &info);
if (ret == 0)
{
utim.actime = info.st_atime;
utim.modtime = timestamp;
ret2 = utime(full_filename, &utim);

Copilot AI Jan 21, 2026

Copy link

Choose a reason for hiding this comment

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

The code uses POSIX utime() and struct utimbuf without Windows-specific handling. On Windows, these may not be available or may need to use _utime() and struct _utimbuf instead. Consider adding platform-specific code or using a more portable approach like utimensat/futimens on systems that support them, or adding Windows-specific equivalents with conditional compilation.

Copilot uses AI. Check for mistakes.
Comment thread src/unshield.c
Comment on lines +552 to +579
if (success && set_timestamp)
{
time_t timestamp = unshield_file_timestamp(unshield, index);
int ret = 0, ret2 = 0;
struct utimbuf utim;
struct stat info;

if (!timestamp)
{
fprintf(stderr, "Failed to get timestamp for file '%s'.", filename);
}
else
{
memset(&utim, 0, sizeof(utim));
memset(&info, 0, sizeof(info));

ret = stat(full_filename, &info);
if (ret == 0)
{
utim.actime = info.st_atime;
utim.modtime = timestamp;
ret2 = utime(full_filename, &utim);
}

if (ret < 0 || ret2 < 0)
fprintf(stderr, "Failed to set timestamp for file '%s'.", filename);
}
}

Copilot AI Jan 21, 2026

Copy link

Choose a reason for hiding this comment

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

The new timestamp setting functionality (-t flag) lacks test coverage. Consider adding tests that verify: 1) timestamps are correctly set when the -t flag is used, 2) extraction still works when timestamps cannot be set, 3) the timestamp values match expected DOS date/time conversions. This would help ensure the feature works correctly across different platforms and edge cases.

Copilot uses AI. Check for mistakes.
TheComputerGuy96 and others added 3 commits October 18, 2026 19:16
These were originally present in the early unshield code but
for some reason they were removed later (this change is based
on the i5comp and i6comp struct layout)

Those struct members have a correct date with the Baldur's Gate
test (likely <IS6?) and GTA San Andreas (IS9)
This also adds a helper function to load the DOS date/time into a tm
structure and an library function to get the ISO 8601 date

Co-authored-by: GitHub Copilot <copilot@github.com>
This also adds an API function for getting an Unix timestamp
(and updates the man page)

Co-authored-by: GitHub Copilot <copilot@github.com>
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 20 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fa9c9516-faa6-4d76-9094-ab39cf35becf
📥 Commits

Reviewing files that changed from the base of the PR and between feaa32f and e37cde0.

📒 Files selected for processing: 10
  • lib/cabfile.h
  • lib/file.c
  • lib/helper.c
  • lib/internal.h
  • lib/libunshield.h
  • man/unshield.1
  • src/unshield.c
  • test/CMakeLists.txt
  • test/timestamps.c
  • test/timestamps.cmake
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@twogood

twogood commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

What this change does: Exposes archive timestamps, displays dates when listing files, and adds opt-in timestamp preservation during extraction. This is a meaningful user-facing feature.

Must fix: The project warning-as-error build fails at filename = unshield_file_name(...): filename is char *, while the accessor returns const char *. I reproduced this with the project's -Wall -Werror -Wpedantic flags.

Must fix: The filename refactor now leaves filename uninitialized until after directory construction, but earlier allocation/path/conversion failures jump to exit, which prints it with %s. Initialize the borrowed filename before any such exit (or retain the accessor call in the error message).

Must fix: Missing/invalid DOS dates are treated as successful dates. A zeroed descriptor produced 1900-01-00 00:00:00; unshield_file_timestamp() returned (time_t)-1 on this machine. The CLI checks only for zero, so it passes the conversion failure to utime(). Validate date fields and reject failed mktime() results before changing file timestamps.

The existing suite passes without warning-as-error flags (24/24), but none of those tests checks timestamp behavior. A valid-date probe produced the expected 2024-06-15 12:34:56.

Verdict: Worth finishing; fix the three issues and add valid/missing-date extraction tests before merging.


Branch update correction: The initial update used a force-pushed rebase. The original PR commits have now been restored as first-parent history with a merge commit, pushed normally without force. Both the original and previously rebased commits remain reachable. The reviewed file contents are unchanged.

Review basis: main 313534b (after #199), with current logging, assertions, I/O callbacks, and GCC 14/15 CI preserved in conflict resolutions. No functional fixes to the findings above were folded into the branch update. Local checks used macOS arm64, shared Debug builds with bundled MD5 unless stated otherwise; native MSVC and glibc runtime checks were not performed.

Restore the original contribution commits as the first-parent history.
Keep the reviewed conflict resolutions and current main without rewriting published history again.
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.

[Request] Timestamp preservation

3 participants