mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-25 09:11:28 -05:00
removed duplicate hashing function. Now the hash buffer is always 512 bytes.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4038 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
acf536317f
commit
9de341953d
@ -846,7 +846,7 @@ void FileIndexMonitor::hashFiles(const std::vector<DirContentToHash>& to_hash)
|
|||||||
//
|
//
|
||||||
if(useHashCache && hashCache.find(real_path,fe.size,fe.modtime,fe.hash))
|
if(useHashCache && hashCache.find(real_path,fe.size,fe.modtime,fe.hash))
|
||||||
fi.updateFileEntry(to_hash[i].dirpath,fe,stamp);
|
fi.updateFileEntry(to_hash[i].dirpath,fe,stamp);
|
||||||
else if(RsDirUtil::hashFile(real_path, fe.hash)) // not found, then hash it.
|
else if(RsDirUtil::getFileHash(real_path, fe.hash,fe.size)) // not found, then hash it.
|
||||||
{
|
{
|
||||||
RsStackMutex stack(fiMutex); /**** LOCKED DIRS ****/
|
RsStackMutex stack(fiMutex); /**** LOCKED DIRS ****/
|
||||||
|
|
||||||
|
@ -278,6 +278,8 @@ int ftFileCreator::locked_initializeFileAttrs()
|
|||||||
}
|
}
|
||||||
ftFileCreator::~ftFileCreator()
|
ftFileCreator::~ftFileCreator()
|
||||||
{
|
{
|
||||||
|
std::cerr << "Deleting file creator for " << file_name << std::endl;
|
||||||
|
|
||||||
// Note: The file is actually closed in the parent, that is always a ftFileProvider.
|
// Note: The file is actually closed in the parent, that is always a ftFileProvider.
|
||||||
//
|
//
|
||||||
/*
|
/*
|
||||||
@ -495,6 +497,7 @@ bool ftFileCreator::finished()
|
|||||||
|
|
||||||
bool ftFileCreator::hashReceivedData(std::string& hash)
|
bool ftFileCreator::hashReceivedData(std::string& hash)
|
||||||
{
|
{
|
||||||
|
std::cerr << "file creator " << hash << " asked for hashing received data " << file_name << std::endl;
|
||||||
// csoler: No mutex here please !
|
// csoler: No mutex here please !
|
||||||
//
|
//
|
||||||
// This is a bit dangerous, but otherwise we might stuck the GUI for a
|
// This is a bit dangerous, but otherwise we might stuck the GUI for a
|
||||||
@ -502,9 +505,13 @@ bool ftFileCreator::hashReceivedData(std::string& hash)
|
|||||||
// at a time file_name nor hash can be modified, which is easy.
|
// at a time file_name nor hash can be modified, which is easy.
|
||||||
//
|
//
|
||||||
if(!finished())
|
if(!finished())
|
||||||
|
{
|
||||||
|
std::cerr << "Transfer not finished !! This should not happen" << std::endl;
|
||||||
return false ;
|
return false ;
|
||||||
|
}
|
||||||
|
|
||||||
return RsDirUtil::hashFile(file_name,hash) ;
|
uint64_t tmpsize ;
|
||||||
|
return RsDirUtil::getFileHash(file_name,hash,tmpsize) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ftFileCreator::crossCheckChunkMap(const CRC32Map& ref,uint32_t& bad_chunks,uint32_t& incomplete_chunks)
|
bool ftFileCreator::crossCheckChunkMap(const CRC32Map& ref,uint32_t& bad_chunks,uint32_t& incomplete_chunks)
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
/******
|
/******
|
||||||
* #define FT_DEBUG 1
|
* #define FT_DEBUG 1
|
||||||
*****/
|
*****/
|
||||||
|
#define FT_DEBUG 1
|
||||||
|
|
||||||
#include "retroshare/rsturtle.h"
|
#include "retroshare/rsturtle.h"
|
||||||
#include "fttransfermodule.h"
|
#include "fttransfermodule.h"
|
||||||
|
@ -54,7 +54,6 @@
|
|||||||
/****
|
/****
|
||||||
* #define RSDIR_DEBUG 1
|
* #define RSDIR_DEBUG 1
|
||||||
****/
|
****/
|
||||||
#define RSDIR_DEBUG 1
|
|
||||||
|
|
||||||
std::string RsDirUtil::getTopDir(const std::string& dir)
|
std::string RsDirUtil::getTopDir(const std::string& dir)
|
||||||
{
|
{
|
||||||
@ -157,74 +156,6 @@ bool RsDirUtil::crc32File(FILE *fd, uint64_t file_size,uint32_t chunk_size, CRC3
|
|||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsDirUtil::hashFile(const std::string& f_hash, std::string& hash)
|
|
||||||
{
|
|
||||||
FILE *fd;
|
|
||||||
int len;
|
|
||||||
SHA_CTX *sha_ctx = new SHA_CTX;
|
|
||||||
unsigned char sha_buf[SHA_DIGEST_LENGTH];
|
|
||||||
unsigned char *gblBuf = new unsigned char[1024*1024*10]; // 10MB buffer.
|
|
||||||
|
|
||||||
#ifdef FIM_DEBUG
|
|
||||||
std::cerr << "File to hash = " << f_hash << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WINDOWS_SYS
|
|
||||||
std::wstring wf_hash;
|
|
||||||
librs::util::ConvertUtf8ToUtf16(f_hash, wf_hash);
|
|
||||||
if (NULL == (fd = _wfopen(wf_hash.c_str(), L"rb")))
|
|
||||||
goto hashing_failed ;
|
|
||||||
#else
|
|
||||||
if (NULL == (fd = fopen64(f_hash.c_str(), "rb")))
|
|
||||||
goto hashing_failed ;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SHA1_Init(sha_ctx);
|
|
||||||
while((len = fread(gblBuf,1, 512, fd)) > 0)
|
|
||||||
{
|
|
||||||
SHA1_Update(sha_ctx, gblBuf, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* reading failed for some reason */
|
|
||||||
if (ferror(fd))
|
|
||||||
{
|
|
||||||
#ifdef FIM_DEBUG
|
|
||||||
std::cerr << "read error !!" << std::endl;
|
|
||||||
#endif
|
|
||||||
goto hashing_failed ;
|
|
||||||
}
|
|
||||||
|
|
||||||
SHA1_Final(&sha_buf[0], sha_ctx);
|
|
||||||
|
|
||||||
/* TODO: Actually we should store the hash data as binary ...
|
|
||||||
* but then it shouldn't be put in a string.
|
|
||||||
*/
|
|
||||||
|
|
||||||
{
|
|
||||||
std::ostringstream tmpout;
|
|
||||||
for(int i = 0; i < SHA_DIGEST_LENGTH; i++)
|
|
||||||
{
|
|
||||||
tmpout << std::setw(2) << std::setfill('0') << std::hex << (unsigned int) (sha_buf[i]);
|
|
||||||
}
|
|
||||||
hash = tmpout.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
delete sha_ctx;
|
|
||||||
delete[] gblBuf ;
|
|
||||||
fclose(fd);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
hashing_failed:
|
|
||||||
|
|
||||||
delete sha_ctx;
|
|
||||||
delete[] gblBuf ;
|
|
||||||
|
|
||||||
if(fd != NULL)
|
|
||||||
fclose(fd) ;
|
|
||||||
|
|
||||||
return false ;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string RsDirUtil::removeTopDir(const std::string& dir)
|
std::string RsDirUtil::removeTopDir(const std::string& dir)
|
||||||
{
|
{
|
||||||
std::string rest;
|
std::string rest;
|
||||||
@ -595,8 +526,7 @@ bool RsDirUtil::hashFile(const std::string& filepath,
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
/* Function to hash, and get details of a file */
|
/* Function to hash, and get details of a file */
|
||||||
bool RsDirUtil::getFileHash(const std::string& filepath,
|
bool RsDirUtil::getFileHash(const std::string& filepath, std::string &hash, uint64_t &size)
|
||||||
std::string &hash, uint64_t &size)
|
|
||||||
{
|
{
|
||||||
FILE *fd;
|
FILE *fd;
|
||||||
int len;
|
int len;
|
||||||
|
@ -42,8 +42,6 @@ std::string removeRootDir(const std::string& path);
|
|||||||
std::string removeTopDir(const std::string& dir);
|
std::string removeTopDir(const std::string& dir);
|
||||||
std::string removeRootDirs(const std::string& path, const std::string& root);
|
std::string removeRootDirs(const std::string& path, const std::string& root);
|
||||||
|
|
||||||
bool hashFile(const std::string& full_path,std::string& hash) ;
|
|
||||||
|
|
||||||
// Renames file from to file to. Files should be on the same file system.
|
// Renames file from to file to. Files should be on the same file system.
|
||||||
// returns true if succeed, false otherwise.
|
// returns true if succeed, false otherwise.
|
||||||
bool renameFile(const std::string& from,const std::string& to) ;
|
bool renameFile(const std::string& from,const std::string& to) ;
|
||||||
@ -65,11 +63,8 @@ bool checkDirectory(const std::string& dir);
|
|||||||
bool checkCreateDirectory(const std::string& dir);
|
bool checkCreateDirectory(const std::string& dir);
|
||||||
bool cleanupDirectory(const std::string& dir, const std::list<std::string> &keepFiles);
|
bool cleanupDirectory(const std::string& dir, const std::list<std::string> &keepFiles);
|
||||||
|
|
||||||
bool hashFile(const std::string& filepath,
|
bool hashFile(const std::string& filepath, std::string &name, std::string &hash, uint64_t &size);
|
||||||
std::string &name, std::string &hash, uint64_t &size);
|
bool getFileHash(const std::string& filepath,std::string &hash, uint64_t &size);
|
||||||
|
|
||||||
bool getFileHash(const std::string& filepath,
|
|
||||||
std::string &hash, uint64_t &size);
|
|
||||||
|
|
||||||
|
|
||||||
std::wstring getWideTopDir(std::wstring);
|
std::wstring getWideTopDir(std::wstring);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user