mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-11 02:25:34 -04:00
- implemented post-download hash re-check. For now, if the hash does not match, the download is canceled, but in the near future, per-chunk comparison wil occur
. - corrected a bug that caused file copy error: a closeFile() was missing when the file is complete. Because of delays in fwrite, the file would not be always co mplete, nor exist at all for small files (e.g. cache files), which in the later case caused the copy error. Warning: needs a make clean in libretroshare to recompile. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3261 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
225781aa51
commit
458a8faf70
10 changed files with 329 additions and 117 deletions
|
@ -2,6 +2,7 @@
|
|||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <util/rsdiscspace.h>
|
||||
#include <util/rsdir.h>
|
||||
|
||||
/*******
|
||||
* #define FILE_DEBUG 1
|
||||
|
@ -102,50 +103,62 @@ bool ftFileCreator::addFileData(uint64_t offset, uint32_t chunk_size, void *data
|
|||
if(!RsDiscSpace::checkForDiscSpace(RS_PARTIALS_DIRECTORY))
|
||||
return false ;
|
||||
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
||||
if (fd == NULL)
|
||||
if (!locked_initializeFileAttrs())
|
||||
return false;
|
||||
|
||||
/*
|
||||
* check its at the correct location
|
||||
*/
|
||||
if (offset + chunk_size > mSize)
|
||||
bool complete = false ;
|
||||
{
|
||||
chunk_size = mSize - offset;
|
||||
std::cerr <<"Chunk Size greater than total file size, adjusting chunk " << "size " << chunk_size << std::endl;
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
||||
}
|
||||
if (fd == NULL)
|
||||
if (!locked_initializeFileAttrs())
|
||||
return false;
|
||||
|
||||
/*
|
||||
* go to the offset of the file
|
||||
*/
|
||||
if (0 != fseeko64(this->fd, offset, SEEK_SET))
|
||||
{
|
||||
std::cerr << "ftFileCreator::addFileData() Bad fseek at offset " << offset << ", fd=" << (void*)(this->fd) << ", size=" << mSize << ", errno=" << errno << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (1 != fwrite(data, chunk_size, 1, this->fd))
|
||||
{
|
||||
std::cerr << "ftFileCreator::addFileData() Bad fwrite." << std::endl;
|
||||
std::cerr << "ERRNO: " << errno << std::endl;
|
||||
/*
|
||||
* check its at the correct location
|
||||
*/
|
||||
if (offset + chunk_size > mSize)
|
||||
{
|
||||
chunk_size = mSize - offset;
|
||||
std::cerr <<"Chunk Size greater than total file size, adjusting chunk " << "size " << chunk_size << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* go to the offset of the file
|
||||
*/
|
||||
if (0 != fseeko64(this->fd, offset, SEEK_SET))
|
||||
{
|
||||
std::cerr << "ftFileCreator::addFileData() Bad fseek at offset " << offset << ", fd=" << (void*)(this->fd) << ", size=" << mSize << ", errno=" << errno << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (1 != fwrite(data, chunk_size, 1, this->fd))
|
||||
{
|
||||
std::cerr << "ftFileCreator::addFileData() Bad fwrite." << std::endl;
|
||||
std::cerr << "ERRNO: " << errno << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef FILE_DEBUG
|
||||
std::cerr << "ftFileCreator::addFileData() added Data...";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << " pos: " << offset;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "ftFileCreator::addFileData() added Data...";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << " pos: " << offset;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
/*
|
||||
* Notify ftFileChunker about chunks received
|
||||
*/
|
||||
locked_notifyReceived(offset,chunk_size);
|
||||
/*
|
||||
* Notify ftFileChunker about chunks received
|
||||
*/
|
||||
locked_notifyReceived(offset,chunk_size);
|
||||
|
||||
complete = chunkMap.isComplete();
|
||||
}
|
||||
if(complete)
|
||||
{
|
||||
#ifdef FILE_DEBUG
|
||||
std::cerr << "ftFileCreator::addFileData() File is complete: closing" << std::endl ;
|
||||
#endif
|
||||
closeFile();
|
||||
}
|
||||
|
||||
/*
|
||||
* FIXME HANDLE COMPLETION HERE - Any better way?
|
||||
*/
|
||||
|
@ -451,3 +464,17 @@ bool ftFileCreator::finished()
|
|||
return chunkMap.isComplete() ;
|
||||
}
|
||||
|
||||
bool ftFileCreator::hashReceivedData(std::string& hash)
|
||||
{
|
||||
RsStackMutex stack(ftcMutex) ;
|
||||
|
||||
return RsDirUtil::hashFile(file_name,hash) ;
|
||||
}
|
||||
|
||||
#include <stdexcept>
|
||||
bool ftFileCreator::crossCheckChunkMap(const CRC32Map& ref)
|
||||
{
|
||||
// still to be implemented.
|
||||
throw std::runtime_error(std::string("Unimplemented function ") + __PRETTY_FUNCTION__) ;
|
||||
return true ;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue