From 7d810e632719b9d910200c382a98d12252d40264 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Mon, 17 Apr 2023 19:01:31 -0400 Subject: ustar, main: Show mode and mtime --- diff --git a/TODO b/TODO index 95eefcf..31e6a3c 100644 --- a/TODO +++ b/TODO @@ -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? diff --git a/src/main.c b/src/main.c index 3d92850..84ff164 100644 --- a/src/main.c +++ b/src/main.c @@ -19,6 +19,7 @@ #include #include +#include #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 * -- cgit v0.9.1