]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Improve the shell tool ".ar --list --verbose" command.
authordan <dan@noemail.net>
Wed, 27 Dec 2017 21:13:21 +0000 (21:13 +0000)
committerdan <dan@noemail.net>
Wed, 27 Dec 2017 21:13:21 +0000 (21:13 +0000)
FossilOrigin-Name: b64681a644c419bb98d00980a6cb56ef5a0aff5ef5321955631f0b4c88aac283

ext/misc/zipfile.c
manifest
manifest.uuid
src/shell.c.in

index cf9666a7aebe95ae70de28983c028c28bef63ebe..188d4fc2ea81ac20df15f48643c68a3bc7d39b3a 100644 (file)
@@ -50,6 +50,9 @@ typedef unsigned long u32;
 
 #define ZIPFILE_BUFFER_SIZE (64*1024)
 
+
+#define ZIPFILE_EXTRA_TIMESTAMP 0x5455
+
 /*
 ** Set the error message contained in context ctx to the results of
 ** vprintf(zFmt, ...).
@@ -341,7 +344,14 @@ static int zipfileReadCDS(ZipfileCsr *pCsr){
         pCsr->iNextOff += pCsr->cds.nComment;
       }
 
-      /* Scan the "extra" fields */
+      /* Scan the cds.nExtra bytes of "extra" fields for any that can
+      ** be interpreted. The general format of an extra field is:
+      **
+      **   Header ID    2 bytes
+      **   Data Size    2 bytes
+      **   Data         N bytes
+      **
+      */
       if( rc==SQLITE_OK ){
         u8 *p = &aRead[pCsr->cds.nFile];
         u8 *pEnd = &p[pCsr->cds.nExtra];
@@ -351,7 +361,7 @@ static int zipfileReadCDS(ZipfileCsr *pCsr){
           u16 nByte = zipfileRead16(p);
 
           switch( id ){
-            case 0x5455: {        /* Extended timestamp */
+            case ZIPFILE_EXTRA_TIMESTAMP: {
               u8 b = p[0];
               if( b & 0x01 ){     /* 0x01 -> modtime is present */
                 pCsr->mTime = zipfileGetU32(&p[1]);
@@ -359,9 +369,6 @@ static int zipfileReadCDS(ZipfileCsr *pCsr){
               }
               break;
             }
-
-            case 0x7875:          /* Info-ZIP Unix (new) */
-              break;
           }
 
           p += nByte;
index 0cc3ca2bdd724ef83d3dfd94a4a5d84e3517dcd3..d6c9a543e59efe317dc3cae57121a152a411ab90 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Have\sthe\sshell\stool\s".ar\s--list"\sand\s".ar\s--extract"\scommands\ssupport\szip\nfiles.\sCurrently\sthe\s"-zip"\sswitch\sis\srequired.
-D 2017-12-27T18:54:11.166
+C Improve\sthe\sshell\stool\s".ar\s--list\s--verbose"\scommand.
+D 2017-12-27T21:13:21.423
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F Makefile.in ceb40bfcb30ebba8e1202b34c56ff7e13e112f9809e2381d99be32c2726058f5
@@ -302,7 +302,7 @@ F ext/misc/vfsstat.c bf10ef0bc51e1ad6756629e1edb142f7a8db1178
 F ext/misc/vtablog.c 31d0d8f4406795679dcd3a67917c213d3a2a5fb3ea5de35f6e773491ed7e13c9
 F ext/misc/vtshim.c 1976e6dd68dd0d64508c91a6dfab8e75f8aaf6cd
 F ext/misc/wholenumber.c 784b12543d60702ebdd47da936e278aa03076212
-F ext/misc/zipfile.c 96148b78b56664fe82f774e50dcdf6c83d693a1449b88011eba00cd6c697fedf
+F ext/misc/zipfile.c ced1aa768904cf8182c3da93d42df4e3cf30fe7a2e66c9216f6bc64a8df4fd5b
 F ext/rbu/rbu.c ea7d1b7eb44c123a2a619332e19fe5313500705c4a58aaa1887905c0d83ffc2e
 F ext/rbu/rbu1.test 43836fac8c7179a358eaf38a8a1ef3d6e6285842
 F ext/rbu/rbu10.test 1846519a438697f45e9dcb246908af81b551c29e1078d0304fae83f1fed7e9ee
@@ -483,7 +483,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
 F src/resolve.c bbee7e31d369a18a2f4836644769882e9c5d40ef4a3af911db06410b65cb3730
 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
 F src/select.c 8b22abe193e4d8243befa2038e4ae2405802fed1c446e5e502d11f652e09ba74
-F src/shell.c.in d1be3030ee7afbbfb67972e4614b6d08dcae2e76460114d6b200fd28d0f008fb
+F src/shell.c.in 9177b6cc706b1dd1ed81b05344641597d7ed8bba97a8fc31192309189846fab7
 F src/sqlite.h.in 2126192945019d4cdce335cb236b440a05ec75c93e4cd94c9c6d6e7fcc654cc4
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h c02d628cca67f3889c689d82d25c3eb45e2c155db08e4c6089b5840d64687d34
@@ -1692,7 +1692,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 8e366b99b13d765d8bf000a7ec5919e582702e51dc07c27a746b6002898a2302
-R 0d0cb33644ad535bd9f83812fd2ec78d
+P a532a0f6fd59e81086d46f09151ba7fb26725198231d902c71d0f95cb01dbe91
+R 7075030d907b0ffe212621eb709bb967
 U dan
-Z 54715bdb695d1dc399a9b1cd512f6d24
+Z 1c430e112380037cc2bfad44bf8be92e
index 6167e93eb4de2839639298507197b00dbbbbba32..aaba04f0ece8f6c1b4ccbb72e4255855ea0b045c 100644 (file)
@@ -1 +1 @@
-a532a0f6fd59e81086d46f09151ba7fb26725198231d902c71d0f95cb01dbe91
\ No newline at end of file
+b64681a644c419bb98d00980a6cb56ef5a0aff5ef5321955631f0b4c88aac283
\ No newline at end of file
index 15a018bb9c9a023208f5888538a98095ad3be6c0..f7edb53f06b569a9544a18786c890c395ec0a5f5 100644 (file)
@@ -4577,12 +4577,43 @@ static void arWhereClause(
   *pzWhere = zWhere;
 }
 
+/*
+** Argument zMode must point to a buffer at least 11 bytes in size. This
+** function populates this buffer with the string interpretation of
+** the unix file mode passed as the second argument (e.g. "drwxr-xr-x").
+*/
+static void shellModeToString(char *zMode, int mode){
+  int i;
+
+  /* Magic numbers copied from [man 2 stat] */
+  if( mode & 0040000 ){
+    zMode[0] = 'd';
+  }else if( (mode & 0120000)==0120000 ){
+    zMode[0] = 'l';
+  }else{
+    zMode[0] = '-';
+  }
+
+  for(i=0; i<3; i++){
+    int m = (mode >> ((2-i)*3));
+    char *a = &zMode[1 + i*3];
+    a[0] = (m & 0x4) ? 'r' : '-';
+    a[1] = (m & 0x2) ? 'w' : '-';
+    a[2] = (m & 0x1) ? 'x' : '-';
+  }
+  zMode[10] = '\0';
+}
+
 /*
 ** Implementation of .ar "lisT" command. 
 */
 static int arListCommand(ShellState *p, sqlite3 *db, ArCommand *pAr){
-  const char *zSql = "SELECT name FROM %s WHERE %s"; 
+  const char *zSql = "SELECT %s FROM %s WHERE %s"; 
   const char *zTbl = (pAr->bZip ? "zipfile(?)" : "sqlar");
+  const char *azCols[] = {
+    "name",
+    "mode, sz, datetime(mtime, 'unixepoch'), name"
+  };
 
   char *zWhere = 0;
   sqlite3_stmt *pSql = 0;
@@ -4591,12 +4622,23 @@ static int arListCommand(ShellState *p, sqlite3 *db, ArCommand *pAr){
   rc = arCheckEntries(db, pAr);
   arWhereClause(&rc, pAr, &zWhere);
 
-  shellPreparePrintf(db, &rc, &pSql, zSql, zTbl, zWhere);
+  shellPreparePrintf(db, &rc, &pSql, zSql, azCols[pAr->bVerbose], zTbl, zWhere);
   if( rc==SQLITE_OK && pAr->bZip ){
     sqlite3_bind_text(pSql, 1, pAr->zFile, -1, SQLITE_TRANSIENT);
   }
   while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
-    raw_printf(p->out, "%s\n", sqlite3_column_text(pSql, 0));
+    if( pAr->bVerbose ){
+      char zMode[11];
+      shellModeToString(zMode, sqlite3_column_int(pSql, 0));
+
+      raw_printf(p->out, "%s % 10d  %s  %s\n", zMode,
+          sqlite3_column_int(pSql, 1), 
+          sqlite3_column_text(pSql, 2),
+          sqlite3_column_text(pSql, 3)
+      );
+    }else{
+      raw_printf(p->out, "%s\n", sqlite3_column_text(pSql, 0));
+    }
   }
 
   shellFinalize(&rc, pSql);