mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-09 06:42:19 -04:00
corrected the file copy error (see trunk commit 3261
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5.0@3266 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
f082b0b45f
commit
d786eda784
1 changed files with 48 additions and 36 deletions
|
@ -102,49 +102,61 @@ bool ftFileCreator::addFileData(uint64_t offset, uint32_t chunk_size, void *data
|
||||||
if(!RsDiscSpace::checkForDiscSpace(RS_PARTIALS_DIRECTORY))
|
if(!RsDiscSpace::checkForDiscSpace(RS_PARTIALS_DIRECTORY))
|
||||||
return false ;
|
return false ;
|
||||||
|
|
||||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
bool complete = false ;
|
||||||
|
|
||||||
if (fd == NULL)
|
|
||||||
if (!locked_initializeFileAttrs())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* check its at the correct location
|
|
||||||
*/
|
|
||||||
if (offset + chunk_size > mSize)
|
|
||||||
{
|
{
|
||||||
chunk_size = mSize - offset;
|
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||||
std::cerr <<"Chunk Size greater than total file size, adjusting chunk " << "size " << chunk_size << std::endl;
|
|
||||||
|
|
||||||
}
|
if (fd == NULL)
|
||||||
|
if (!locked_initializeFileAttrs())
|
||||||
|
return false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* go to the offset of the file
|
* check its at the correct location
|
||||||
*/
|
*/
|
||||||
if (0 != fseeko64(this->fd, offset, SEEK_SET))
|
if (offset + chunk_size > mSize)
|
||||||
{
|
{
|
||||||
std::cerr << "ftFileCreator::addFileData() Bad fseek at offset " << offset << ", fd=" << (void*)(this->fd) << ", size=" << mSize << ", errno=" << errno << std::endl;
|
chunk_size = mSize - offset;
|
||||||
return 0;
|
std::cerr <<"Chunk Size greater than total file size, adjusting chunk " << "size " << chunk_size << std::endl;
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
/*
|
||||||
}
|
* 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
|
#ifdef FILE_DEBUG
|
||||||
std::cerr << "ftFileCreator::addFileData() added Data...";
|
std::cerr << "ftFileCreator::addFileData() added Data...";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
std::cerr << " pos: " << pos;
|
std::cerr << " pos: " << pos;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* Notify ftFileChunker about chunks received
|
* Notify ftFileChunker about chunks received
|
||||||
*/
|
*/
|
||||||
locked_notifyReceived(offset,chunk_size);
|
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?
|
* FIXME HANDLE COMPLETION HERE - Any better way?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue