mirror of
https://github.com/uroni/urbackup_backend.git
synced 2025-10-26 11:36:50 +00:00
Better settings exchange
This commit is contained in:
parent
1efc662c4a
commit
58128df764
@ -86,4 +86,7 @@ bool CDBSettingsReader::getValue(std::wstring key, std::wstring *value)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::wstring> CDBSettingsReader::getKeys()
|
||||
{
|
||||
return std::vector<std::wstring>();
|
||||
}
|
||||
|
||||
@ -10,6 +10,8 @@ public:
|
||||
bool getValue(std::string key, std::string *value);
|
||||
bool getValue(std::wstring key, std::wstring *value);
|
||||
|
||||
std::vector<std::wstring> getKeys();
|
||||
|
||||
private:
|
||||
std::string table;
|
||||
|
||||
|
||||
@ -142,4 +142,17 @@ void CFileSettingsReader::cleanup()
|
||||
void CFileSettingsReader::setup()
|
||||
{
|
||||
settings_mutex=Server->createMutex();
|
||||
}
|
||||
|
||||
std::vector<std::wstring> CFileSettingsReader::getKeys()
|
||||
{
|
||||
IScopedLock lock(cached_settings->smutex);
|
||||
|
||||
std::vector<std::wstring> ret;
|
||||
for(std::map<std::wstring,std::wstring>::iterator i=cached_settings->mSettingsMap.begin();
|
||||
i!=cached_settings->mSettingsMap.end();++i)
|
||||
{
|
||||
ret.push_back(i->first);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -30,6 +30,8 @@ public:
|
||||
static void cleanup();
|
||||
static void setup();
|
||||
|
||||
virtual std::vector<std::wstring> CFileSettingsReader::getKeys();
|
||||
|
||||
private:
|
||||
|
||||
static std::map<std::string, SCachedSettings*> *settings;
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
#define INTERFACE_SETTINGSREADER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Object.h"
|
||||
|
||||
class ISettingsReader : public IObject
|
||||
@ -19,6 +20,8 @@ public:
|
||||
virtual std::wstring getValue(std::wstring key)=0;
|
||||
virtual int getValue(std::wstring key, int def)=0;
|
||||
virtual float getValue(std::wstring key, float def)=0;
|
||||
|
||||
virtual std::vector<std::wstring> getKeys() = 0;
|
||||
};
|
||||
|
||||
#endif //INTERFACE_SETTINGSREADER_H
|
||||
@ -71,3 +71,13 @@ bool CMemorySettingsReader::getValue(std::wstring key, std::wstring *value)
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
std::vector<std::wstring> CMemorySettingsReader::getKeys()
|
||||
{
|
||||
std::vector<std::wstring> ret;
|
||||
for(std::map<std::wstring,std::wstring>::iterator i=mSettingsMap.begin();i!=mSettingsMap.end();++i)
|
||||
{
|
||||
ret.push_back(i->first);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -10,6 +10,8 @@ public:
|
||||
virtual bool getValue(std::string key, std::string *value);
|
||||
virtual bool getValue(std::wstring key, std::wstring *value);
|
||||
|
||||
virtual std::vector<std::wstring> getKeys();
|
||||
|
||||
private:
|
||||
std::map<std::wstring,std::wstring> mSettingsMap;
|
||||
};
|
||||
@ -1116,6 +1116,7 @@ void ClientConnector::updateSettings(const std::string &pData)
|
||||
|
||||
std::vector<std::wstring> settings_names=getSettingsList();
|
||||
settings_names.push_back(L"client_set_settings");
|
||||
settings_names.push_back(L"client_set_settings_time");
|
||||
std::wstring new_settings_str=L"";
|
||||
bool mod=false;
|
||||
std::string tmp_str;
|
||||
@ -1247,20 +1248,69 @@ void ClientConnector::replaceSettings(const std::string &pData)
|
||||
data.addVoidPtr(NULL);
|
||||
IndexThread::getMsgPipe()->Write(data.getDataPtr(), data.getDataSize());
|
||||
}
|
||||
|
||||
Server->destroy(new_settings);
|
||||
IFile *sf=Server->openFile("urbackup/data/settings.cfg", MODE_WRITE);
|
||||
if(sf==NULL)
|
||||
|
||||
ISettingsReader* old_settings=Server->createFileSettingsReader("urbackup/data/settings.cfg");
|
||||
|
||||
std::vector<std::wstring> new_keys = new_settings->getKeys();
|
||||
bool modified_settings=true;
|
||||
if(old_settings!=NULL)
|
||||
{
|
||||
Server->Log("Error opening settings file!", LL_ERROR);
|
||||
return;
|
||||
modified_settings=false;
|
||||
std::vector<std::wstring> old_keys = old_settings->getKeys();
|
||||
|
||||
for(size_t i=0;i<old_keys.size();++i)
|
||||
{
|
||||
std::wstring old_val;
|
||||
std::wstring new_val;
|
||||
if( old_settings->getValue(old_keys[i], &old_val) &&
|
||||
(!new_settings->getValue(old_keys[i], &new_val) ||
|
||||
old_val!=new_val ) )
|
||||
{
|
||||
modified_settings=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!modified_settings)
|
||||
{
|
||||
for(size_t i=0;i<new_keys.size();++i)
|
||||
{
|
||||
std::wstring old_val;
|
||||
if(!old_settings->getValue(new_keys[i], &old_val))
|
||||
{
|
||||
modified_settings=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Server->destroy(old_settings);
|
||||
}
|
||||
sf->Write(pData);
|
||||
if(pData.find("\r\nclient_set_settings=true")==std::string::npos)
|
||||
{
|
||||
sf->Write("\r\nclient_set_settings=true");
|
||||
|
||||
if(modified_settings)
|
||||
{
|
||||
std::string new_data;
|
||||
|
||||
for(size_t i=0;i<new_keys.size();++i)
|
||||
{
|
||||
if(new_keys[i]==L"client_set_settings" ||
|
||||
new_keys[i]==L"client_set_settings_time")
|
||||
continue;
|
||||
|
||||
std::wstring val;
|
||||
if(new_settings->getValue(new_keys[i], &val))
|
||||
{
|
||||
new_data+=Server->ConvertToUTF8(new_keys[i])+"="+Server->ConvertToUTF8(val)+"\n";
|
||||
}
|
||||
}
|
||||
|
||||
new_data+="client_set_settings=true\n";
|
||||
new_data+="client_set_settings_time="+nconvert(Server->getTimeSeconds())+"\n";
|
||||
|
||||
writestring(new_data, "urbackup/data/settings.cfg");
|
||||
}
|
||||
Server->destroy(sf);
|
||||
|
||||
Server->destroy(new_settings);
|
||||
}
|
||||
|
||||
void ClientConnector::saveLogdata(const std::string &created, const std::string &pData)
|
||||
|
||||
@ -179,7 +179,6 @@ bool isDirectory(const std::wstring &path)
|
||||
int rc=stat64(Server->ConvertToUTF8(path).c_str(), &f_info);
|
||||
if(rc!=0)
|
||||
{
|
||||
Server->Log(L"No permission to access \""+path+L"\" (isdir)", LL_DEBUG);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -64,10 +64,6 @@ std::vector<std::wstring> getSettingsList(void)
|
||||
std::vector<std::wstring> getOnlyServerClientSettingsList(void)
|
||||
{
|
||||
std::vector<std::wstring> ret;
|
||||
ret.push_back(L"backup_window_incr_file");
|
||||
ret.push_back(L"backup_window_full_file");
|
||||
ret.push_back(L"backup_window_incr_image");
|
||||
ret.push_back(L"backup_window_full_image");
|
||||
ret.push_back(L"silent_update");
|
||||
ret.push_back(L"client_quota");
|
||||
ret.push_back(L"local_full_file_transfer_mode");
|
||||
|
||||
@ -1552,7 +1552,7 @@ bool BackupServerGet::doFullBackup(bool with_hashes, bool &disk_error, bool &log
|
||||
return false;
|
||||
}
|
||||
|
||||
IFile *tmp=getTemporaryFileRetry();;
|
||||
IFile *tmp=getTemporaryFileRetry();
|
||||
if(tmp==NULL)
|
||||
{
|
||||
ServerLogger::Log(clientid, L"Error creating temporary file in ::doFullBackup", LL_ERROR);
|
||||
@ -3479,6 +3479,10 @@ void BackupServerGet::sendSettings(void)
|
||||
|
||||
if(!key.empty())
|
||||
{
|
||||
if(!allow_overwrite)
|
||||
{
|
||||
s_settings+=Server->ConvertToUTF8(key)+"="+Server->ConvertToUTF8(value)+"\n";
|
||||
}
|
||||
key+=L"_def";
|
||||
s_settings+=Server->ConvertToUTF8(key)+"="+Server->ConvertToUTF8(value)+"\n";
|
||||
}
|
||||
@ -3543,6 +3547,24 @@ bool BackupServerGet::getClientSettings(bool& doesnt_exist)
|
||||
bool b=updateClientSetting(L"client_set_settings", L"true");
|
||||
if(b)
|
||||
mod=true;
|
||||
|
||||
std::wstring settings_update_time;
|
||||
if(sr->getValue(L"client_set_settings_time", &settings_update_time))
|
||||
{
|
||||
b=updateClientSetting(L"client_set_settings_time", settings_update_time);
|
||||
if(b)
|
||||
{
|
||||
mod=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Server->destroy(sr);
|
||||
std::string tmp_fn=tmp->getFilename();
|
||||
Server->destroy(tmp);
|
||||
Server->deleteFile(tmp_fn);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user