removed duplicate copy/rename file methods from ftController

This commit is contained in:
mr-alice 2016-11-22 23:39:09 +01:00
parent 47b825833a
commit fb70cb2e9e
5 changed files with 48 additions and 120 deletions

View file

@ -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)
{

View file

@ -84,6 +84,8 @@ const char *scanf_string_for_uint(int bytes) ;
int breakupDirList(const std::string& path, std::list<std::string> &subdirs);
bool copyFile(const std::string& source,const std::string& dest);
bool moveFile(const std::string& source,const std::string& dest);
bool removeFile(const std::string& file);
bool fileExists(const std::string& file);
bool checkFile(const std::string& filename,uint64_t& file_size,bool disallow_empty_file = false);
bool checkDirectory(const std::string& dir);