Ejemplo n.º 1
0
 /*------------------------------------------------------------------------------*
   Get md5sum signature of file (used ofr OLD storage based on file)
  *------------------------------------------------------------------------------*/
 QString Database::getMd5sumSignature(QString filename)
 {
     const int BLOCK_SIZE=1024*1024;
     QFile file(filename);
     QCryptographicHash md5Hash(QCryptographicHash::Md5);
     if (file.open(QIODevice::ReadOnly | QIODevice::Unbuffered))
     {
         while (!file.atEnd())
         {
             md5Hash.addData(file.read(BLOCK_SIZE));
         }
     }
     file.close();
     return md5Hash.result().toHex();
 } //Database::getMd5sumSignature
Ejemplo n.º 2
0
bool StarMgr::checkAndLoadCatalog(const QVariantMap& catDesc)
{
	const bool checked = catDesc.value("checked").toBool();
	QString catalogFileName = catDesc.value("fileName").toString();

	// See if it is an absolute path, else prepend default path
	if (!(StelFileMgr::isAbsolute(catalogFileName)))
		catalogFileName = "stars/default/"+catalogFileName;

	QString catalogFilePath = StelFileMgr::findFile(catalogFileName);
	if (catalogFilePath.isEmpty())
	{
		// The file is supposed to be checked, but we can't find it
		if (checked)
		{
			qWarning() << QString("Warning: could not find star catalog %1").arg(QDir::toNativeSeparators(catalogFileName));
			setCheckFlag(catDesc.value("id").toString(), false);
		}
		return false;
	}
	// Possibly fixes crash on Vista
	if (!StelFileMgr::isReadable(catalogFilePath))
	{
		qWarning() << QString("Warning: User does not have permissions to read catalog %1").arg(QDir::toNativeSeparators(catalogFilePath));
		return false;
	}

	if (!checked)
	{
		// The file is not checked but we found it, maybe from a previous download/version
		qWarning() << "Found file " << QDir::toNativeSeparators(catalogFilePath) << ", checking md5sum..";

		QFile fic(catalogFilePath);
		if(fic.open(QIODevice::ReadOnly | QIODevice::Unbuffered))
		{
			// Compute the MD5 sum
			QCryptographicHash md5Hash(QCryptographicHash::Md5);
			const qint64 cat_sz = fic.size();
			qint64 maxStarBufMd5 = qMin(cat_sz, 9223372036854775807LL);
			uchar *cat = maxStarBufMd5 ? fic.map(0, maxStarBufMd5) : NULL;
			if (!cat)
			{
				// The OS was not able to map the file, revert to slower not mmap based method
				static const qint64 maxStarBufMd5 = 1024*1024*8;
				char* mmd5buf = (char*)malloc(maxStarBufMd5);
				while (!fic.atEnd())
				{
					qint64 sz = fic.read(mmd5buf, maxStarBufMd5);
					md5Hash.addData(mmd5buf, sz);
				}
				free(mmd5buf);
			}
			else
			{
				md5Hash.addData((const char*)cat, cat_sz);
				fic.unmap(cat);
			}
			fic.close();
			if (md5Hash.result().toHex()!=catDesc.value("checksum").toByteArray())
			{
				qWarning() << "Error: File " << QDir::toNativeSeparators(catalogFileName) << " is corrupt, MD5 mismatch! Found " << md5Hash.result().toHex() << " expected " << catDesc.value("checksum").toByteArray();
				fic.remove();
				return false;
			}
			qWarning() << "MD5 sum correct!";
			setCheckFlag(catDesc.value("id").toString(), true);
		}
	}

	ZoneArray* z = ZoneArray::create(catalogFilePath, true);
	if (z)
	{
		if (z->level<gridLevels.size())
		{
			qWarning() << QDir::toNativeSeparators(catalogFileName) << ", " << z->level << ": duplicate level";
			delete z;
			return true;
		}
		Q_ASSERT(z->level==maxGeodesicGridLevel+1);
		Q_ASSERT(z->level==gridLevels.size());
		++maxGeodesicGridLevel;
		gridLevels.append(z);
	}
	return true;
}
Ejemplo n.º 3
0
//PUT 
void putFile(char * filename){

    int fd;
    long int len;
    int part, finalpart;
    struct stat fileStat; 

    char command[MAXLINE] = "";
    char path[MAXLINE] = "";
    char strLength[BUFSIZ] = "";

    //Add Path to File Name
    strcat(path, "./");
    strcat(path, filename);

    printf("File Name: %s \n", path );

    //Open File for Reading
    fd = open(path, O_RDONLY);
    if (fd == -1) {
        printf("Error opening file!\n");
        return;
    }

    //Split File Into Parts
    fstat(fd, &fileStat);

    sprintf(strLength, "%d\n", fileStat.st_size);

    len = atoi(strLength);

    if(len>NUM_SERVERS){
        part = len/NUM_SERVERS;
    }

    finalpart = (len - (part*NUM_SERVERS)) + part;

    //Determine Mapping for File Part to Server

    //Inital Location Each Part is going
    long int adjust = 0;

    adjust = md5Hash(filename);

    // printf("Sum: %d\n", adjust );

    adjust = adjust % 4;

    // printf("Adjust: %d\n", adjust );

    int p1a = (0+adjust) % 4;
    int p1b = (3+adjust) % 4;

    int p2a = (0+adjust) % 4;
    int p2b = (1+adjust) % 4;
    
    int p3a = (1+adjust) % 4;
    int p3b = (2+adjust) % 4;

    int p4a = (2+adjust) % 4;
    int p4b = (3+adjust) % 4;


    close(fd);

    fd = open(path, O_RDONLY);
    if (fd == -1) {
        printf("Error opening file!\n");
        return;
    }

    //Write Part 1
    sprintf(command, "PUT %s %s %s.1\n", userName, passwd, filename);
    writeFile(p1a,p1b,fd,part,command);

    //Write Part 2
    sprintf(command, "PUT %s %s %s.2\n", userName, passwd, filename);
    writeFile(p2a,p2b,fd,part,command);

    //Write Part 3
    sprintf(command, "PUT %s %s %s.3\n", userName, passwd, filename);
    writeFile(p3a,p3b,fd,part,command);

    //Write Part 4
    sprintf(command, "PUT %s %s %s.4\n", userName, passwd, filename);
    writeFile(p4a,p4b,fd,finalpart,command);

    close(fd);

    // printf("Finished PUTing\n");
}