mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
rename file in partials into real name before moving it; check for destination directory before moving file
This commit is contained in:
parent
acbcba8a64
commit
99e35b131c
3 changed files with 67 additions and 6 deletions
|
@ -734,13 +734,39 @@ bool ftController::completeFile(const RsFileHash& hash)
|
|||
|
||||
fc->mState = ftFileControl::COMPLETED;
|
||||
|
||||
std::string dst_dir,src_dir,src_file,dst_file ;
|
||||
|
||||
RsDirUtil::splitDirFromFile(fc->mCurrentPath,src_dir,src_file) ;
|
||||
RsDirUtil::splitDirFromFile(fc->mDestination,dst_dir,dst_file) ;
|
||||
|
||||
// We use this intermediate file in case the destination directory is not available, so as to not keep the partial file name.
|
||||
|
||||
std::string intermediate_file_name = src_dir+'/'+dst_file ;
|
||||
|
||||
// I don't know how the size can be zero, but believe me, this happens,
|
||||
// and it causes an error on linux because then the file may not even exist.
|
||||
//
|
||||
if( fc->mSize > 0 && RsDirUtil::moveFile(fc->mCurrentPath,fc->mDestination) )
|
||||
fc->mCurrentPath = fc->mDestination;
|
||||
else
|
||||
if( fc->mSize == 0)
|
||||
fc->mState = ftFileControl::ERROR_COMPLETION;
|
||||
else
|
||||
{
|
||||
std::cerr << "CompleteFile(): renaming " << fc->mCurrentPath << " into " << fc->mDestination << std::endl;
|
||||
std::cerr << "CompleteFile(): 1 - renaming " << fc->mCurrentPath << " info " << intermediate_file_name << std::endl;
|
||||
|
||||
if(RsDirUtil::moveFile(fc->mCurrentPath,intermediate_file_name) )
|
||||
{
|
||||
fc->mCurrentPath = intermediate_file_name ;
|
||||
|
||||
std::cerr << "CompleteFile(): 2 - renaming/copying " << intermediate_file_name << " into " << fc->mDestination << std::endl;
|
||||
|
||||
if(RsDirUtil::moveFile(intermediate_file_name,fc->mDestination) )
|
||||
fc->mCurrentPath = fc->mDestination;
|
||||
else
|
||||
fc->mState = ftFileControl::ERROR_COMPLETION;
|
||||
}
|
||||
else
|
||||
fc->mState = ftFileControl::ERROR_COMPLETION;
|
||||
}
|
||||
|
||||
/* for extralist additions */
|
||||
path = fc->mDestination;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue