错误:无法通过'...'传递非平凡复制类型'class boost :: filesystem :: path'的对象

时间:2019-03-15 16:51:59

标签: c++ boost

错误:

  

init.cpp:在函数'bool AppInit2()'中:

     

init.cpp:608:83:错误:无法通过'...'传递非平凡复制类型'class boost :: filesystem :: path'的对象

     

printf(“创建%s的备份->%s \ n”,sourceFile,backupFile);

     

init.cpp:608:83:错误:无法通过'...'传递非平凡复制类型'class boost :: filesystem :: path'的对象

     

init.cpp:643:76:错误:无法将参数'2'的'boost :: filesystem :: path'转换为'const char *'到'int sprintf(char *,const char *,... )'

     

sprintf(“旧备份已删除:%s \ n”,file.second);

     

make:*** [obj / init.o]错误1

filesystem::path backupDir = GetDataDir() / "backups";
if (!filesystem::exists(backupDir))
{
    // Always create backup folder to not confuse the operating system's file browser
    filesystem::create_directories(backupDir);
}
nWalletBackups = GetArg("-createwalletbackups", 10);
nWalletBackups = std::max(0, std::min(10, nWalletBackups));
if(nWalletBackups > 0)
{
    if (filesystem::exists(backupDir))
    {
        // Create backup of the wallet
        std::string dateTimeStr = DateTimeStrFormat(".%Y-%m-%d-%H.%M", GetTime());
        std::string backupPathStr = backupDir.string();
        backupPathStr += "/" + strWalletFileName;
        std::string sourcePathStr = GetDataDir().string();
        sourcePathStr += "/" + strWalletFileName;
        boost::filesystem::path sourceFile = sourcePathStr;
        boost::filesystem::path backupFile = backupPathStr + dateTimeStr;
        sourceFile.make_preferred();
        backupFile.make_preferred();
        try {
            boost::filesystem::copy_file(sourceFile, backupFile);
            printf("Creating backup of %s -> %s\n", sourceFile, backupFile);
        } catch(boost::filesystem::filesystem_error &error) {
            printf("Failed to create backup %s\n", error.what());
        }
        // Keep only the last 10 backups, including the new one of course
        typedef std::multimap<std::time_t, boost::filesystem::path> folder_set_t;
        folder_set_t folder_set;
        boost::filesystem::directory_iterator end_iter;
        boost::filesystem::path backupFolder = backupDir.string();
        backupFolder.make_preferred();
        // Build map of backup files for current(!) wallet sorted by last write time
        boost::filesystem::path currentFile;
        for (boost::filesystem::directory_iterator dir_iter(backupFolder); dir_iter != end_iter; ++dir_iter)
        {
            // Only check regular files
            if ( boost::filesystem::is_regular_file(dir_iter->status()))
            {
                currentFile = dir_iter->path().filename();
                // Only add the backups for the current wallet, e.g. wallet.dat.*
                if(currentFile.string().find(strWalletFileName) != string::npos)
                {
                    folder_set.insert(folder_set_t::value_type(boost::filesystem::last_write_time(dir_iter->path()),
     

* dir_iter));                       }                   }               }               //循环浏览备份文件并保留N个最新文件(1 <= N <= 10)               int计数器= 0;               BOOST_REVERSE_FOREACH(PAIRTYPE(const std :: time_t,boost :: filesystem :: path)文件,folder_set)               {                   计数器++;                   如果(计数器> nWalletBackups)                   {                       //超过nWalletBackups个备份:删除最旧的备份                       尝试{                           boost :: filesystem :: remove(file.second);                           sprintf(“旧备份已删除:%s \ n”,file.second);                       } catch(boost :: filesystem :: filesystem_error&error){                           sprintf(“无法删除备份%s \ n”,error.what());                       }                   }               }           }       }

1 个答案:

答案 0 :(得分:0)

朋友的@πάνταῥεῖ答案解决了我的问题!

std::cout << "Creating backup of" << sourceFile << "->" << backupFile << '\n';

std::cout << "Old backup deleted:" << file.second << '\n';

非常感谢您!