mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-20 23:10:39 -04:00
removed duplicate copy/rename file methods from ftController
This commit is contained in:
parent
47b825833a
commit
fb70cb2e9e
5 changed files with 48 additions and 120 deletions
|
@ -36,6 +36,7 @@
|
|||
#include "util/rsmemory.h"
|
||||
#include "util/folderiterator.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "retroshare/rsnotify.h"
|
||||
#include "rsthreads.h"
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
@ -238,6 +239,49 @@ bool RsDirUtil::fileExists(const std::string& filename)
|
|||
return ( access( filename.c_str(), F_OK ) != -1 );
|
||||
}
|
||||
|
||||
bool RsDirUtil::moveFile(const std::string& source,const std::string& dest)
|
||||
{
|
||||
// First try a rename
|
||||
//
|
||||
|
||||
if(renameFile(source,dest))
|
||||
return true ;
|
||||
|
||||
// If not, try to copy. The src and dest probably belong to different file systems
|
||||
|
||||
if(!copyFile(source,dest))
|
||||
return false ;
|
||||
|
||||
// copy was successful, let's delete the original
|
||||
|
||||
if(!removeFile(source))
|
||||
return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool RsDirUtil::removeFile(const std::string& filename)
|
||||
{
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "deleting original file " << source << std::endl ;
|
||||
#endif
|
||||
|
||||
#ifdef WINDOWS_SYS
|
||||
std::wstring filenameW;
|
||||
librs::util::ConvertUtf8ToUtf16(filename,filenameW);
|
||||
|
||||
if(0 != DeleteFileW(filenameW.c_str()))
|
||||
#else
|
||||
if(0 == remove(filename.c_str()))
|
||||
#endif
|
||||
return true ;
|
||||
else
|
||||
{
|
||||
std::cerr << "(EE) File erase error while removing file " << filename << ". Read-only file system ?" << std::endl;
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
|
||||
/**** Copied and Tweaked from ftcontroller ***/
|
||||
bool RsDirUtil::copyFile(const std::string& source,const std::string& dest)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue