void QArchive::finishMessage() { Q_D(QArchive); d->estimate(); d->out_msg=QObject::tr("Finished: ") + QString::number(d->numFiles)+ QLatin1String(" ") +QObject::tr("files") + QLatin1String("\n") + QString(size2str(d->processedSize))+d->max_str + QLatin1String("\n"); d->extra_msg=QObject::tr("Speed: ") + QString(size2str(d->processedSize/(1+d->elapsed)*1000)) + QLatin1String("/s\n") + QObject::tr("Elapsed: %1s Remaining: %2s").arg(g_time_convert(d->elapsed)).arg(g_time_convert(d->left)); killTimer(d->tid); emit finished(); emit textChanged(d->out_msg+d->extra_msg); qApp->processEvents(); }
void QArchive::setArchive(const QString &name) { //QFileInfo(name).absoluteFilePath(); if(isOpen()) close(); #if (QT_VERSION >= 0x040000) setFileName(name); #else this->QFile::setName(name); #endif Q_D(QArchive); d->totalSize = size(); d->max_str=QString(" / %1").arg(size2str(d->totalSize)); }
int main(int argc, char *argv[]) { off_t sz; struct stat sb; char buf[80]; prog = basename(argv[0]); if (argc != 2) { fprintf(stderr, "Usage: %s [file|string]\n", prog); exit(1); } if (stat(argv[1], &sb) < 0) { if (*argv[1] == '/') { fprintf(stderr, "%s: could not stat special file\n", prog); exit(1); } sz = str2size(argv[1]); if (sz == 0) { fprintf(stderr, "%s: error parsing size string\n", prog); exit(1); } } else { if (S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode)) { if (getsize(argv[1], &sz) < 0) { fprintf(stderr, "%s: %s: %s\n", prog, argv[1], strerror(errno)); exit(1); } } else { sz = sb.st_size; } } if (sz != 0) { size2str(buf, sizeof(buf), sz); printf("%s\n", buf); } exit(0); }
void SrvDTP::recvFile(const char *pathname, uint32_t nslice, uint32_t sindex, uint16_t slicecap) { Packet & packet = *(this->ppacket); char buf[MAXLINE]; if (psrvPI->getFilesize() > getDiskAvailable()) { packet.sendSTAT_ERR("insufficient disk space"); return; } if ( psrvPI->setFp(fopen(pathname, "ab")) == NULL) { // send STAT_ERR Response // GNU-specific strerror_r: char *strerror_r(int errnum, char *buf, size_t buflen); packet.sendSTAT_ERR(strerror_r(errno, buf, MAXLINE)); return; } else { if( (flock(fileno(psrvPI->getFp()), LOCK_EX | LOCK_NB)) < 0) { Error::ret("flock"); packet.sendSTAT_ERR(strerror_r(errno, buf, MAXLINE)); return; } off64_t n; off64_t curpos = sindex * slicecap; if ( ( n = lseek64(fileno(psrvPI->getFp()), curpos, SEEK_SET)) < 0) { packet.sendSTAT_ERR(strerror_r(errno, buf, MAXLINE)); return; } else { printf("Recv file [%s %u/%u] now\n", pathname, sindex, nslice); // send STAT_OK packet.sendSTAT_OK(); } } int m; int oldProgress = 0, newProgress = 0; string hfilesize = size2str(psrvPI->getFilesize()); while (psrvPI->recvOnePacket()) { if(packet.getTagid() == TAG_DATA && packet.getDataid() == DATA_FILE){ m = fwrite(packet.getBody(), sizeof(char), packet.getBsize(), psrvPI->getFp()); if (m != packet.getBsize()) { Error::msg("Recieved slice %d/%d: %d vs %d Bytes\n", packet.getSindex(), packet.getNslice(), packet.getBsize(), m); return; } newProgress = (packet.getSindex()*1.0)/packet.getNslice()*100; if (newProgress > oldProgress) { //printf("\033[2K\r\033[0m%-40s%10s\t%3d%%", pathname, hfilesize.c_str(), newProgress); snprintf(buf, MAXLINE, "\033[2K\r\033[0m%-40s%10s\t%3d%%", psrvPI->getClipath().c_str(), hfilesize.c_str(), newProgress); packet.sendSTAT_PGS(buf); } oldProgress = newProgress; //printf("Recieved packet %d: %d vs %d Bytes\n", packet.ps->sindex, packet.ps->bsize, m); } else if(packet.getTagid() == TAG_STAT) { if (packet.getStatid() == STAT_EOF) { if( (flock(fileno(psrvPI->getFp()), LOCK_UN )) < 0 ) { Error::ret("flock"); } Fclose(&psrvPI->getFp()); std::cout << packet.getSBody() << std::endl; // ThreadArg * pthreadArg = new ThreadArg; // pthread_t tid; // pthreadArg->pdb = psrvPI->getPDB(); // snprintf(pthreadArg->buf, MAXLINE, "%s", pathname); // Pthread_create(&tid, NULL, &md5sumThreadFunc, pthreadArg); if (psrvPI->getFilesize() > (256 * 1024 *1024)) // > 256M { packet.sendSTAT(STAT_WAIT, "MD5 computing..."); } insertNewFileMD5SUM(pathname, psrvPI->getPDB()); printf("EOT [%s]\n", pathname); packet.sendSTAT_EOT(" Done"); //insertNewFileMD5SUM(pathname, psrvPI->getPDB()); return; //continue; } else if (packet.getStatid() == STAT_EOT){ std::cout << packet.getSBody() << std::endl; return; } else { Error::msg("SrvDTP::recvFile TAG_STAT: unknown statid %d", packet.getStatid()); return; } } else { Error::msg("SrvDTP::recvFile: unknown tagid %d with statid %d", packet.getTagid(), packet.getStatid()); //packet.print(); return; } } }
int main(int argc, char *argv[]) { confent_t *conf; int c; int dopt = 0; int popt = 0; unsigned long bsize = 1024*1024; char *fsname = NULL; List qlist; int Fopt = 0; int ropt = 0; int sopt = 0; int Hopt = 0; int Uopt = 0; int nopt = 0; int hopt = 0; List uids = NULL; char *conf_path = _PATH_QUOTA_CONF; conf_t config; prog = basename(argv[0]); while ((c = GETOPT(argc, argv, OPTIONS, longopts)) != EOF) { switch(c) { case 'd': /* --dirscan */ dopt++; break; case 'p': /* --pwscan */ popt++; break; case 'b': /* --blocksize */ if (parse_blocksize(optarg, &bsize)) { fprintf(stderr, "%s: error parsing blocksize\n", prog); exit(1); } break; case 'u': /* --uid-range */ uids = listint_create(optarg); if (uids == NULL) { fprintf(stderr, "%s: error parsing uid-range\n", prog); exit(1); } break; case 'r': /* --reverse */ ropt++; break; case 'F': /* --files-sort */ Fopt++; break; case 's': /* --space-sort */ sopt++; break; case 'U': /* --usage-only */ Uopt++; break; case 'H': /* --suppress-heading */ Hopt++; break; case 'f': /* --config */ conf_path = optarg; break; case 'T': /* --selftest */ #ifndef NDEBUG listint_test(); exit(0); #else fprintf(stderr, "%s: not built with debugging enabled\n", prog); exit(1); #endif break; case 'D': /* --debug */ debug = 1; break; case 'n': /* --nouserlookup */ nopt = 1; break; case 'h': /* --human-readable */ hopt = 1; break; default: usage(); } } if (Fopt && sopt) { fprintf(stderr, "%s: -f and -s are mutually exclusive\n", prog); exit(1); } if (popt && dopt) { fprintf(stderr, "%s: -p and -d are mutually exclusive\n", prog); exit(1); } if (!popt && !dopt && !uids) { fprintf(stderr, "%s: need at least one of -pdu\n", prog); exit(1); } if (optind < argc) fsname = argv[optind++]; else usage(); if (optind < argc) usage(); config = conf_init(conf_path); /* exit/perror on error */ if (!(conf = conf_get_bylabel(config, fsname, 0))) { fprintf(stderr, "%s: %s: not found in quota.conf\n", prog, fsname); exit(1); } /* Scan. */ qlist = list_create((ListDelF)quota_destroy); if (popt) pwscan(conf, qlist, uids, !nopt); if (dopt) dirscan(conf, qlist, uids, !nopt); if (!dopt && !popt) uidscan(conf, qlist, uids, !nopt); /* Sort. */ if (ropt) { if (sopt) list_sort(qlist, (ListCmpF)quota_cmp_bytes_reverse); else if (Fopt) list_sort(qlist, (ListCmpF)quota_cmp_files_reverse); else list_sort(qlist, (ListCmpF)quota_cmp_uid_reverse); } else { if (sopt) list_sort(qlist, (ListCmpF)quota_cmp_bytes); else if (Fopt) list_sort(qlist, (ListCmpF)quota_cmp_files); else list_sort(qlist, (ListCmpF)quota_cmp_uid); } /* Report. */ if (!Hopt) { if (hopt) printf("Quota report for %s\n", fsname); else { char tmpstr[16]; size2str(bsize, tmpstr, sizeof(tmpstr)); printf("Quota report for %s (blocksize %s)\n", fsname, tmpstr); } } if (Uopt) { if (!Hopt) quota_report_heading_usageonly(); if (hopt) list_for_each(qlist, (ListForF)quota_report_usageonly_h, &bsize); else list_for_each(qlist, (ListForF)quota_report_usageonly, &bsize); } else { if (!Hopt) quota_report_heading(); if (hopt) list_for_each(qlist, (ListForF)quota_report_h, &bsize); else list_for_each(qlist, (ListForF)quota_report, &bsize); } if (qlist) list_destroy(qlist); if (uids) listint_destroy(uids); conf_fini(config); return 0; }