rc_t ccat_sra ( CCContainerNode *np, const KFile *sf, const char *name ) { rc_t rc; CCSra * sra; rc = CCSraInit (&sra, &np->sub, sf, name); if (rc == 0) { list_adata ldata; list_adata_init (&ldata); rc = step_through_dir (sra->adir, ".", list_action, &ldata); if (rc == 0) { DBGMSG (DBG_APP, 1, ("Vector sizes list (%u) sort (%u)\n", VectorLength(&ldata.list), VectorLength(&ldata.sort))); VectorDoUntil (&ldata.sort, false, CCSraOneItem, sra); /* VectorDoUntil (&ldata.list, false, CCSraOneItem, sra); */ } list_adata_whack (&ldata); CCSraWhack (sra); } DBGMSG (DBG_APP, 1, ("Done with %s\n", name)); return rc; }
static rc_t run_kar_extract (const char * archive, const char * directory) { rc_t rc; const KDirectory * din; KDirectory * dout; STSMSG (1, ("run_kar_extract")); rc = open_file_as_dir (archive, &din); if (rc == 0 ) { char * directorystr; rc = derive_directory_name (&directorystr, archive, directory); if (rc != 0) { ; /* PLOGERR (klogDebug1, (klogDebug1, rc, "failure to derive archive [$(A)/$(D)]", */ /* PLOG_2(PLOG_S(A),PLOG_S(D)), archive, directory)); */ } else { rc = open_out_dir (directorystr, &dout); free (directorystr); if (rc != 0) { LOGERR (klogErr, rc, "failure to open output directory"); } else { extract_adata adata; adata.dir = dout; adata.filter = pnamesFilter; adata.fdata = NULL; rc = step_through_dir (din, ".", pnamesFilter, NULL, extract_action, &adata); KDirectoryRelease (dout); } } KDirectoryRelease (din); } return rc; }
static rc_t CC list_action (const KDirectory * dir, const char * path, void * _adata) { rc_t rc; list_adata * data; list_item * item; KPathType type; uint32_t access; uint64_t size; uint64_t loc; KTime_t mtime; size_t pathlen; size_t linklen; char link [2 * 4096]; /* we'll truncate? */ rc = 0; data = _adata; loc = size = 0; pathlen = strlen (path); type = KDirectoryPathType (dir, path); if (type & kptAlias) { rc = KDirectoryVResolveAlias (dir, false, link, sizeof (link), path, NULL); if (rc == 0) linklen = strlen (link); } else { linklen = 0; switch (type & ~kptAlias) { case kptNotFound: rc = RC (rcExe, rcDirectory, rcAccessing, rcPath, rcNotFound); break; case kptBadPath: rc = RC (rcExe, rcDirectory, rcAccessing, rcPath, rcInvalid); break; case kptZombieFile: if ( ! long_list ) return 0; data->has_zombies = true; case kptFile: rc = KDirectoryFileSize (dir, &size, path); if (rc == 0) { if (size > data->max_size) data->max_size = size; rc = KDirectoryFileLocator (dir, &loc, path); if ((rc == 0) && (loc > data->max_loc)) data->max_loc = loc; } break; case kptDir: break; case kptCharDev: case kptBlockDev: case kptFIFO: /* shouldn't get here */ return 0; } } if (rc == 0) { rc = KDirectoryAccess (dir, &access, "%s", path); if (rc == 0) { rc = KDirectoryDate (dir, &mtime, "%s", path); if (rc == 0) { item = malloc (sizeof (*item) + pathlen + linklen + 2); /* usually one too many */ if (item == NULL) { rc = RC (rcExe, rcNoTarg, rcAllocating, rcMemory, rcExhausted); } else { item->type = type; item->access = access; item->size = size; item->loc = loc; item->mtime = mtime; item->path = (char *)(item+1); strcpy (item->path, path); if (type & kptAlias) { item->link = item->path + pathlen + 1; strcpy (item->link, link); } else item->link = NULL; DLListPushHead (&data->list, &item->dad); if (type == kptDir) rc = step_through_dir (dir, path, data->filter, data->fdata, list_action, data); } } } } return rc; }
static rc_t CC extract_action (const KDirectory * dir, const char * path, void * _adata) { rc_t rc; extract_adata * adata; KPathType type; char link [2 * 4096]; /* we'll truncate? */ uint32_t access; rc = 0; adata = _adata; STSMSG (1, ("extract_action: %s\n", path)); type = KDirectoryPathType (dir, path); if (type & kptAlias) { rc = KDirectoryVResolveAlias (dir, false, link, sizeof (link), path, NULL); if (rc == 0) { rc = KDirectoryVAccess (dir, &access, path, NULL); if (rc == 0) { rc = KDirectoryCreateAlias (adata->dir, access, kcmCreate|kcmParents, link, path); } } } else { switch (type & ~kptAlias) { case kptNotFound: rc = RC (rcExe, rcDirectory, rcAccessing, rcPath, rcNotFound); KOutMsg ("%s: %s type kptNotFouns %R\n", __func__, path, rc); break; case kptBadPath: rc = RC (rcExe, rcDirectory, rcAccessing, rcPath, rcInvalid); break; case kptFile: rc = KDirectoryVAccess (dir, &access, path, NULL); if (rc == 0) { const KFile * fin; KFile * fout; rc = KDirectoryVCreateFile (adata->dir, &fout, false, access, kcmCreate|kcmParents, path, NULL); if (rc == 0) { rc = KDirectoryVOpenFileRead (dir, &fin, path, NULL); if (rc == 0) { #if USE_SKEY_MD5_FIX /* KLUDGE!!!! */ size_t pathz, skey_md5z; static const char skey_md5[] = "skey.md5"; pathz = string_size (path); skey_md5z = string_size(skey_md5); if ( pathz >= skey_md5z && strcmp ( & path [ pathz - skey_md5z ], skey_md5 ) == 0 ) rc = copy_file_skey_md5_kludge (fin, fout); else #endif rc = copy_file (fin, fout); KFileRelease (fin); } KFileRelease (fout); } } break; case kptDir: rc = KDirectoryVAccess (dir, &access, path, NULL); if (rc == 0) { rc = KDirectoryCreateDir (adata->dir, 0700, kcmCreate|kcmParents, path, NULL); if (rc == 0) { rc = step_through_dir (dir, path, adata->filter, adata->fdata, extract_action, adata); if (rc == 0) rc = KDirectoryVSetAccess (adata->dir, false, access, 0777, path, NULL); } } break; case kptCharDev: case kptBlockDev: case kptFIFO: /* shouldn't get here */ return 0; } } return rc; }
static rc_t run_kar_test( const char * archive ) { rc_t rc; const KDirectory * din; rc = open_file_as_dir (archive, &din); if (rc == 0) { list_adata adata; adata.max_loc = adata.max_size = 0; adata.filter = pnamesFilter; adata.fdata = NULL; adata.has_zombies = false; DLListInit (&adata.list); /* find all directory entries */ rc = step_through_dir ( din, ".", pnamesFilter, NULL, list_action, &adata ); /* "sort" the file entries if requested */ if (rc == 0) { } if (rc == 0) { const char * LineFormatFile = "%c%s %*lu %*lu %*s %s"; const char * LineFormatEFile = "%c%s %*lu %*c %*s %s"; const char * LineFormatDir = "%c%s %*c %*c %*s %s"; const char * LineFormatTxt = "%c%s %-*s %-*s %-*s %s"; /* 18446744073709551615 is max 64bit unsigned so 20 characters + 1 */ char zwidth_buffer [32]; size_t zwidth, lwidth; union u { DLNode * node; list_item * item; } ptr; rc = string_printf (zwidth_buffer, sizeof zwidth_buffer, & zwidth, "%lu", adata.max_size); rc = string_printf (zwidth_buffer, sizeof zwidth_buffer, & lwidth, "%lu", adata.max_size); if (long_list) { /* need to use time_t not Ktime_t here since we are calling system functions */ time_t t = time(NULL); struct tm * ts = localtime (&t); int dwidth = strftime (zwidth_buffer, sizeof (zwidth_buffer), "%Y-%m-%d %H:%M:%S", ts); KOutMsg (LineFormatTxt, 'T',"ypeAccess", (uint32_t)zwidth, "Size", (uint32_t)lwidth, "Offset", (uint32_t)dwidth, "ModDateTime", "Path Name\n"); } for (ptr.node = DLListPopTail(&adata.list); ptr.node != NULL; ptr.node = DLListPopTail(&adata.list)) { if (long_list) { struct tm * ts; char t; char a[10]; char d[20]; size_t dwidth; time_t lt; lt = ptr.item->mtime; ts = localtime (<); dwidth = strftime (d, sizeof (d), "%Y-%m-%d %H:%M:%S", ts); access_to_string (a, ptr.item->access); if (ptr.item->type & kptAlias) t = 'l'; else if (ptr.item->type == kptDir) t = 'd'; else t = '-'; if ((ptr.item->type & ~kptAlias) == kptZombieFile) KOutMsg(LineFormatFile, t, "TRUNCATED", (uint32_t)zwidth, ptr.item->size, ( uint32_t )lwidth, ptr.item->loc, ( uint32_t )dwidth, d, ptr.item->path); else if ((ptr.item->type & ~kptAlias) == kptFile) { if (ptr.item->size == 0) KOutMsg(LineFormatEFile, t, a, ( uint32_t )zwidth, ptr.item->size, ( uint32_t )lwidth, '-', ( uint32_t )dwidth, d, ptr.item->path); else KOutMsg(LineFormatFile, t, a, ( uint32_t )zwidth, ptr.item->size, ( uint32_t )lwidth, ptr.item->loc, ( uint32_t )dwidth, d, ptr.item->path); } else KOutMsg(LineFormatDir, t, a, ( uint32_t )zwidth, '-', ( uint32_t )lwidth, '-', ( uint32_t )dwidth, d, ptr.item->path); if (ptr.item->type & kptAlias) KOutMsg (" -> %s\n", ptr.item->link); else KOutMsg ("\n"); } else { KOutMsg ("%s\n",ptr.item->path); } } } KDirectoryRelease (din); } return rc; }
static rc_t list_action (const KDirectory * dir, const char * path, void * _adata) { rc_t rc = 0; list_adata * data = _adata; list_item * item = NULL; KPathType type = KDirectoryPathType (dir, "%s", path); size_t pathlen = strlen (path); size_t linklen = 0; char link [2 * 4096]; /* we'll truncate? */ if (type & kptAlias) { rc = KDirectoryVResolveAlias (dir, false, link, sizeof (link), path, NULL); if (rc == 0) linklen = strlen (link); } if (rc == 0) { item = calloc (sizeof (*item) + pathlen + linklen + 2, 1); /* usually one too many */ if (item == NULL) { rc = RC (rcExe, rcNoTarg, rcAllocating, rcMemory, rcExhausted); } else { do { item->path = (char *)(item+1); strcpy (item->path, path); item->type = type; rc = KDirectoryAccess (dir, &item->access, "%s", path); if (rc) break; rc = KDirectoryDate (dir, &item->mtime, "%s", path); if (rc) break; if (type & kptAlias) { item->link = item->path + pathlen + 1; strcpy (item->link, link); } else switch (type & ~kptAlias) { case kptNotFound: rc = RC (rcExe, rcDirectory, rcAccessing, rcPath, rcNotFound); break; case kptBadPath: rc = RC (rcExe, rcDirectory, rcAccessing, rcPath, rcInvalid); break; case kptZombieFile: data->has_zombies = true; case kptFile: rc = KDirectoryFileSize (dir, &item->size, "%s", path); if (rc == 0) rc = KDirectoryFileLocator (dir, &item->loc, "%s", path); DBGMSG (DBG_APP, 1, ("%s: found file %s size %lu at %lu\n", __func__, item->path, item->size, item->loc)); break; case kptDir: DBGMSG (DBG_APP, 1, ("%s: found directory %s\n", __func__, item->path)); break; default: DBGMSG (DBG_APP, 1, ("%s: found unknown %s\n", __func__, item->path)); break; } } while (0); } } if (rc == 0) { VectorAppend (&data->list, NULL, item); VectorInsert (&data->sort, item, NULL, list_item_cmp); if (type == kptDir) rc = step_through_dir (dir, path, list_action, data); } return rc; }