Exemple #1
0
QString sumit(const QString& path, int num_bytes, const QString& temporary_path)
{
    if (num_bytes != 0) {
        return compute_the_file_hash(path, num_bytes);
    }
    //the file id is a hashed function of device,inode,size, and modification time (in seconds)
    //note that it is not dependent on the file name
    struct stat SS;
    stat(path.toLatin1().data(), &SS);

    //didn't compile on mac so using the following which only depends on size and modification date

    QFileInfo info(path);
    QString id_string = QString("%1:%2:%3:%4").arg(path).arg(info.size()).arg(info.lastModified().toMSecsSinceEpoch()).arg(info.size());

    //QString id_string = QString("%1:%2:%3:%4").arg(SS.st_dev).arg(SS.st_ino).arg(SS.st_size).arg(SS.st_mtim.tv_sec);
    QString file_id = compute_the_string_hash(id_string);

    QString dirname = QString(temporary_path + "/sumit/sha1/%1").arg(file_id.mid(0, 4));
    create_directory_if_doesnt_exist(dirname);
    QString hash_path = QString("%1/%2").arg(dirname).arg(file_id);

    QString hash_sum = read_text_file(hash_path);
    if (hash_sum.isEmpty()) {
        create_hash_file(path, hash_path);
        hash_sum = read_text_file(hash_path);
    }
    if (hash_sum.count() != 40) {
        create_hash_file(path, hash_path);
        hash_sum = read_text_file(hash_path);
    }
    return hash_sum;
}
Exemple #2
0
int main(int argc, char *argv[])
{
    FILE *fpInput;
    fpInput=createInFile(argv[1]);
    
    
    FILE *fp;
    
    fp = create_hash_file(FILENAME);
    insertFromInFile(fp, INSERT, &fpInput);
    searchOrInsert(fp, INSERT, &fpInput);
    searchOrInsert(fp, SEARCH, &fpInput);
    searchOrInsert(fp, DELETE, &fpInput);
    searchOrInsert(fp, SEARCH, &fpInput);
    fclose(fpInput);
    fclose(fp);
    
    
    
#ifdef _MSC_VER
    printf( _CrtDumpMemoryLeaks() ? "Memory Leak\n" : "No Memory Leak\n");
#endif
    
    return 0;
}