ZIP_FILE_SET_MTIME(3)

πŸ“¦
version 1.11.4 Β· 3 versions
, in arch rolling, debian trixie, fedora 43, fedora 44, nixpkgs unstable, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– ZIP_FILE_SET_MTIME πŸ’–

okay bestie, we're in ZIP_FILE_SET_MTIME(3), aka the Library Functions Manual, and today's hyperfixation is setting the last modification time (mtime) for a file in a zip. yes. we're doing timestamps. it's giving archival girlboss energy and I am obsessed. πŸŽ€


✨ NAME ✨

zip_file_set_dostime, zip_file_set_mtime β€” set last modification time (mtime) for file in zip

πŸ“š LIBRARY πŸ“š

libzip (-lzip) β€” no cap, that's the one you're linking against.

🫢 SYNOPSIS 🫢

#include <zip.h>

int
zip_file_set_dostime(zip_t *archive, zip_uint64_t index,
    zip_uint16_t dostime, zip_uint16_t dosdate, zip_flags_t flags);

int
zip_file_set_mtime(zip_t *archive, zip_uint64_t index, time_t mtime,
    zip_flags_t flags);

🌸 DESCRIPTION 🌸

so zip_file_set_mtime() sets the last modification time (mtime) for the file sitting at position index in the zip archive, and it sets it to mtime. that's the whole vibe. πŸ’…

Currently, no support for any flags is implemented. β€” literally none, bestie, the flag situation is a void.

here's the tea though: inside the zip archive, the time and date are stored as two 16-bit integers. so if you wanna set those values directly, you call zip_file_set_dostime() instead. here's how the bits are divvied up 🧚

the values of the time bytes are defined as follows:

  • 0-4 β€” seconds divided by two (1-2 = 1, 3-4 = 2, ...)
  • 5-10 β€” minute (0-59)
  • 11-15 β€” hour (0-23)

the values of the date bytes are defined as follows:

  • 0-4 β€” day of the month (1-31)
  • 5-8 β€” month (January = 1, February = 2, ...)
  • 9-15 β€” year offset from 1980 (1980 = 0, 1981 = 1, ...)

look at those little bit ranges. so compact. so iconic. πŸ”₯

πŸ¦‹ RETURN VALUES πŸ¦‹

if it works? you get 0 back. slay. πŸ’–

if it doesn't? you get -1, and the error information in archive gets set to tell you what went wrong. sad girl hours but at least you get diagnostics.

πŸ’€ ERRORS πŸ’€

zip_file_set_dostime() and zip_file_set_mtime() fail if:

  • [ZIP_ER_INVAL] β€” index is not a valid file index in archive. bestie that file does not exist, stop trying to timestamp a ghost πŸ™ˆ
  • [ZIP_ER_MEMORY] β€” required memory could not be allocated. the machine said no 😭
  • [ZIP_ER_OPNOTSUPP] β€” traditional PKWare encryption uses the file's mtime, therefore it cannot be changed without re-encrypting the data. yeah so this one's locked, the encryption literally eats the mtime. you can't just edit it, you'd have to re-encrypt the whole thing.
  • [ZIP_ER_RDONLY] β€” the archive was opened in read-only mode. read-only means read-only, we don't write here βœ‹

πŸ‘‘ SEE ALSO πŸ‘‘

libzip(3), zip_stat(3)

🌈 HISTORY 🌈

  • zip_file_set_mtime() was added in libzip 1.0.
  • zip_file_set_dostime() was added in libzip 1.6.

glow-ups across releases, we love to see it ⭐

πŸŽ€ AUTHORS πŸŽ€

Dieter Baron <dillo@nih.at> and Thomas Klausner <wiz@gatalith.at> β€” the actual main characters who wrote this πŸ’œ

⚠️ CAVEATS ⚠️

following historical practice, the zip_file_set_mtime() function translates the time from the zip archive into the local time zone. if you want to avoid this, use the zip_file_set_dostime() function instead. fr fr, timezone surprises are not the vibe check you want.

and that's the whole page, bestie 🫢 this was written up on June 18, 2022 and shipped out by the Debian girlies under ZIP_FILE_SET_MTIME(3). go set some timestamps, you absolute legend πŸ’…βœ¨