static void outwinname(Biobuf *b, Hist *h, char *ds, char *p) { if(isdelim(p[0])) { // full rooted name zfile(b, ds, 3); // leading "c:/" outzfile(b, p+1); } else { // relative name if(h->offset == 0 && pathname && pathname[1] == ':') { if(tolowerrune(ds[0]) == tolowerrune(pathname[0])) { // using current drive zfile(b, pathname, 3); // leading "c:/" outzfile(b, pathname+3); } else { // using drive other then current, // we don't have any simple way to // determine current working directory // there, therefore will output name as is zfile(b, ds, 2); // leading "c:" } } outzfile(b, p); } }
static void outhist(Biobuf *b) { Hist *h; char *p, ds[] = {'c', ':', '/', 0}; for(h = hist; h != H; h = h->link) { p = h->name; if(p) { if(windows) { // if windows variable is set, then, we know already, // pathname is started with windows drive specifier // and all '\' were replaced with '/' (see lex.c) if(isdelim(p[0]) && isdelim(p[1])) { // file name has network name in it, // like \\server\share\dir\file.go zfile(b, "//", 2); // leading "//" outzfile(b, p+2); } else if(p[1] == ':') { // file name has drive letter in it ds[0] = p[0]; outwinname(b, h, ds, p+2); } else { // no drive letter in file name outwinname(b, h, pathname, p); } } else { if(p[0] == '/') { // full rooted name, like /home/rsc/dir/file.go zfile(b, "/", 1); // leading "/" outzfile(b, p+1); } else { // relative name, like dir/file.go if(h->offset == 0 && pathname && pathname[0] == '/') { zfile(b, "/", 1); // leading "/" outzfile(b, pathname+1); } outzfile(b, p); } } } zhist(b, h->line, h->offset); } }
static void outzfile(Biobuf *b, char *p) { char *q, *q2; while(p) { q = utfrune(p, '/'); if(windows) { q2 = utfrune(p, '\\'); if(q2 && (!q || q2 < q)) q = q2; } if(!q) { zfile(b, p, strlen(p)); return; } if(q > p) zfile(b, p, q-p); p = q + 1; } }
void outhist(Biobuf *b) { Hist *h; char *p, *q, *op; int n; for(h = hist; h != H; h = h->link) { p = h->name; op = 0; if(p && p[0] != '/' && h->offset == 0 && pathname && pathname[0] == '/') { op = p; p = pathname; } while(p) { q = utfrune(p, '/'); if(q) { n = q-p; if(n == 0) n = 1; // leading "/" q++; } else { n = strlen(p); q = 0; } if(n) zfile(b, p, n); p = q; if(p == 0 && op) { p = op; op = 0; } } zhist(b, h->line, h->offset); } }
bool ExportCommon::unzip(ExportContext *ctx, QString file, QString dest) { QDir toPath = QFileInfo( QDir::cleanPath(ctx->outputDir.absoluteFilePath(dest))).dir(); QFile zfile(file); if (!zfile.open(QIODevice::ReadOnly)) { exportError("Can't open file %s\n", file.toStdString().c_str()); return false; } while (true) { struct _ZipHdr { quint32 Signature;// local file header signature 4 bytes (0x04034b50) #define ZIPHDR_SIG 0x04034b50 quint16 Version; // version needed to extract 2 bytes quint16 Flags; // general purpose bit flag 2 bytes quint16 Compression; // compression method 2 bytes quint16 ModTime; // last mod file time 2 bytes quint16 ModDate; // last mod file date 2 bytes quint32 Crc32; // crc-32 4 bytes quint32 CompSize; // compressed size 4 bytes quint32 OrigSize; // uncompressed size 4 bytes quint16 NameLen; // file name length 2 bytes quint16 ExtraLen;// extra field length 2 bytes }PACKED Hdr; if (zfile.read((char *) &Hdr, sizeof(Hdr)) != sizeof(Hdr)) break; if (_letohl(Hdr.Signature) != ZIPHDR_SIG) break; if (_letohs(Hdr.Version) > 20) { exportError("Unsupported ZIP version for %s [%d]\n", file.toStdString().c_str(), _letohs(Hdr.Version)); return false; } if (Hdr.Flags != 0) { exportError("Unsupported flags for %s [%04x]\n", file.toStdString().c_str(), Hdr.Flags); return false; } if ((Hdr.Compression > 0) && (_letohs(Hdr.Compression) != 8)) { exportError("Unsupported compression method for %s [%d]\n", file.toStdString().c_str(), _letohs(Hdr.Compression)); return false; } QByteArray fname = zfile.read(_letohs(Hdr.NameLen)); QString lname = QString(fname); zfile.read(_letohs(Hdr.ExtraLen)); exportInfo("Extracting %s\n",lname.toStdString().c_str()); QByteArray fcont = zfile.read( Hdr.Compression ? _letohl(Hdr.CompSize) : _letohl(Hdr.OrigSize)); if (Hdr.Compression) { QByteArray decomp; if (!gzInflate(fcont,decomp)) { exportError("Failed to uncompress %s\n", lname.toStdString().c_str()); break; } fcont = decomp; } if (lname.endsWith("/")) ctx->outputDir.mkpath(toPath.absoluteFilePath(lname)); else { QFile ofile(toPath.absoluteFilePath(lname)); if (ofile.open(QIODevice::WriteOnly)) { ofile.write(fcont); ofile.close(); } else { exportError("Can't open file %s\n", lname.toStdString().c_str()); break; } } } zfile.close(); return true; }
static void outhist(Biobuf *b) { Hist *h; char *p, ds[] = {'c', ':', '/', 0}; char *tofree; int n; static int first = 1; static char *goroot, *goroot_final; if(first) { // Decide whether we need to rewrite paths from $GOROOT to $GOROOT_FINAL. first = 0; goroot = getenv("GOROOT"); goroot_final = getenv("GOROOT_FINAL"); if(goroot == nil) goroot = ""; if(goroot_final == nil) goroot_final = goroot; if(strcmp(goroot, goroot_final) == 0) { goroot = nil; goroot_final = nil; } } tofree = nil; for(h = hist; h != H; h = h->link) { p = h->name; if(p) { if(goroot != nil) { n = strlen(goroot); if(strncmp(p, goroot, strlen(goroot)) == 0 && p[n] == '/') { tofree = smprint("%s%s", goroot_final, p+n); p = tofree; } } if(windows) { // if windows variable is set, then, we know already, // pathname is started with windows drive specifier // and all '\' were replaced with '/' (see lex.c) if(isdelim(p[0]) && isdelim(p[1])) { // file name has network name in it, // like \\server\share\dir\file.go zfile(b, "//", 2); // leading "//" outzfile(b, p+2); } else if(p[1] == ':') { // file name has drive letter in it ds[0] = p[0]; outwinname(b, h, ds, p+2); } else { // no drive letter in file name outwinname(b, h, pathname, p); } } else { if(p[0] == '/') { // full rooted name, like /home/rsc/dir/file.go zfile(b, "/", 1); // leading "/" outzfile(b, p+1); } else { // relative name, like dir/file.go if(h->offset >= 0 && pathname && pathname[0] == '/') { zfile(b, "/", 1); // leading "/" outzfile(b, pathname+1); } outzfile(b, p); } } } zhist(b, h->line, h->offset); if(tofree) { free(tofree); tofree = nil; } } }