diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-04-17 19:01:31 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-04-17 19:03:15 (EDT) |
commit | 7d810e632719b9d910200c382a98d12252d40264 (patch) | |
tree | 1c1a189e568f2e299dc8f471b40cebe4efd7d8a7 | |
parent | cb5600ac708ddeac608ce47363c43bfd566b26d2 (diff) |
ustar, main: Show mode and mtime
-rw-r--r-- | TODO | 3 | ||||
-rw-r--r-- | src/main.c | 25 | ||||
-rw-r--r-- | src/ustar.c | 11 | ||||
-rw-r--r-- | src/ustar.h | 14 |
4 files changed, 42 insertions, 11 deletions
@@ -1,3 +1,4 @@ -Add missing ustar member fields +Align ustar member fields to max column widths + Linked list of members, save max strlen()s on first pass Add option handling I18n? @@ -19,6 +19,7 @@ #include <stdio.h> #include <stdlib.h> +#include <time.h> #include "defs.h" #include "gzip.h" #include "ustar.h" @@ -150,12 +151,28 @@ _opkg_opk_main_list_members(struct opkg_opk_ustar *ustar) { struct opkg_opk_ustar_member member; int ret; + char mode[10]; + char mtime[20]; while ((ret = opkg_opk_ustar_list(ustar, &member)) == OPKG_OPK_OK) { - printf("%c %32s/%-32s %11d %s\n", - member.type, - member.uname, member.gname, - member.size, member.name); + if (member.mode & 00400) mode[0] = 'r'; else mode[0] = '-'; + if (member.mode & 00200) mode[1] = 'w'; else mode[1] = '-'; + if (member.mode & 00100) mode[2] = 'x'; else mode[2] = '-'; + if (member.mode & 04000) mode[2] = 's'; + if (member.mode & 00040) mode[3] = 'r'; else mode[3] = '-'; + if (member.mode & 00020) mode[4] = 'w'; else mode[4] = '-'; + if (member.mode & 00010) mode[5] = 'x'; else mode[5] = '-'; + if (member.mode & 02000) mode[5] = 's'; + if (member.mode & 00004) mode[6] = 'r'; else mode[6] = '-'; + if (member.mode & 00002) mode[7] = 'w'; else mode[7] = '-'; + if (member.mode & 00001) mode[8] = 'x'; else mode[8] = '-'; + if (member.mode & 01000) mode[8] = 't'; + mode[9] = '\0'; + strftime(mtime, sizeof(mtime), "%Y-%m-%d %H:%M:%S", + localtime(&member.mtime)); + printf("%c%s %32s/%-32s %11d %s %s\n", + member.type, mode, member.uname, member.gname, + member.size, mtime, member.name); } if (ret == OPKG_OPK_ERROR) { fputs("Error: Failed to list data files\n", stderr); diff --git a/src/ustar.c b/src/ustar.c index 7e00cb6..a277f15 100644 --- a/src/ustar.c +++ b/src/ustar.c @@ -145,6 +145,7 @@ opkg_opk_ustar_list(struct opkg_opk_ustar *ustar, { static struct _opkg_opk_ustar_header header; int ret; + char *end; if ((ret =_opkg_opk_ustar_next(ustar, &header)) != OPKG_OPK_OK) { return ret; /* Error or end of archive */ @@ -156,7 +157,17 @@ opkg_opk_ustar_list(struct opkg_opk_ustar *ustar, memcpy(member->name, header.name, sizeof(header.name)); member->name[sizeof(header.name)] = '\0'; } + member->mode = strtol((char *) header.mode, &end, + OPKG_OPK_USTAR_NUM_BASE_); + if (*end != '\0') { + return OPKG_OPK_ERROR; + } member->size = ustar->data_size_remaining; + member->mtime = strtol((char *) header.mtime, &end, + OPKG_OPK_USTAR_NUM_BASE_); + if (*end != '\0') { + return OPKG_OPK_ERROR; + } switch (*header.typeflag) { case '0': /* Regular file */ case '7': /* High-performance or regular file */ diff --git a/src/ustar.h b/src/ustar.h index 6d5049b..7c4c089 100644 --- a/src/ustar.h +++ b/src/ustar.h @@ -29,12 +29,14 @@ struct opkg_opk_ustar; struct opkg_opk_ustar_member { - char name[OPKG_OPK_USTAR_NAME_MAX_LEN]; - int64_t size; - char type; - char linkname[100]; - char uname [32]; - char gname [32]; + char name[OPKG_OPK_USTAR_NAME_MAX_LEN]; + uint16_t mode; + int64_t size; + int64_t mtime; + char type; + char linkname[100]; + char uname [32]; + char gname [32]; }; struct opkg_opk_ustar * |