//BAK_FILE bakFile(fileName, storeSettings.GetRemoveBak());
-Touch(fileName + ".new");
+CONFIGFILE cfstat(fileName, true);
- {
- CONFIGFILE cfstat(fileName + ".new");
+int e = cfstat.Error();
- int e = cfstat.Error();
-
- if (e)
- {
- STG_LOCKER lock(&mutex, __FILE__, __LINE__);
- errorStr = string("User \'") + login + "\' conf not written\n";
- printfd(__FILE__, "FILES_STORE::SaveUserConf - conf write failed for user '%s'\n", login.c_str());
- return -1;
- }
-
- e = chmod(fileName.c_str(), storeSettings.GetConfMode());
- e += chown(fileName.c_str(), storeSettings.GetConfUID(), storeSettings.GetConfGID());
-
- if (e)
- {
- STG_LOCKER lock(&mutex, __FILE__, __LINE__);
- printfd(__FILE__, "FILES_STORE::SaveUserConf - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
- }
+if (e)
+ {
+ STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+ errorStr = string("User \'") + login + "\' conf not written\n";
+ printfd(__FILE__, "FILES_STORE::SaveUserConf - conf write failed for user '%s'\n", login.c_str());
+ return -1;
+ }
- cfstat.WriteString("Password", conf.password);
- cfstat.WriteInt ("Passive", conf.passive);
- cfstat.WriteInt ("Down", conf.disabled);
- cfstat.WriteInt("DisabledDetailStat", conf.disabledDetailStat);
- cfstat.WriteInt ("AlwaysOnline", conf.alwaysOnline);
- cfstat.WriteString("Tariff", conf.tariffName);
- cfstat.WriteString("Address", conf.address);
- cfstat.WriteString("Phone", conf.phone);
- cfstat.WriteString("Email", conf.email);
- cfstat.WriteString("Note", conf.note);
- cfstat.WriteString("RealName", conf.realName);
- cfstat.WriteString("Group", conf.group);
- cfstat.WriteDouble("Credit", conf.credit);
- cfstat.WriteString("TariffChange", conf.nextTariff);
-
- char userdataName[12];
- for (int i = 0; i < USERDATA_NUM; i++)
- {
- snprintf(userdataName, 12, "Userdata%d", i);
- cfstat.WriteString(userdataName, conf.userdata[i]);
- }
- cfstat.WriteInt("CreditExpire", conf.creditExpire);
+e = chmod(fileName.c_str(), storeSettings.GetConfMode());
+e += chown(fileName.c_str(), storeSettings.GetConfUID(), storeSettings.GetConfGID());
- stringstream ipStr;
- ipStr << conf.ips;
- cfstat.WriteString("IP", ipStr.str());
+if (e)
+ {
+ STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+ printfd(__FILE__, "FILES_STORE::SaveUserConf - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
}
-if (rename((fileName + ".new").c_str(), fileName.c_str()) < 0)
+cfstat.WriteString("Password", conf.password);
+cfstat.WriteInt ("Passive", conf.passive);
+cfstat.WriteInt ("Down", conf.disabled);
+cfstat.WriteInt("DisabledDetailStat", conf.disabledDetailStat);
+cfstat.WriteInt ("AlwaysOnline", conf.alwaysOnline);
+cfstat.WriteString("Tariff", conf.tariffName);
+cfstat.WriteString("Address", conf.address);
+cfstat.WriteString("Phone", conf.phone);
+cfstat.WriteString("Email", conf.email);
+cfstat.WriteString("Note", conf.note);
+cfstat.WriteString("RealName", conf.realName);
+cfstat.WriteString("Group", conf.group);
+cfstat.WriteDouble("Credit", conf.credit);
+cfstat.WriteString("TariffChange", conf.nextTariff);
+
+char userdataName[12];
+for (int i = 0; i < USERDATA_NUM; i++)
{
- STG_LOCKER lock(&mutex, __FILE__, __LINE__);
- errorStr = "Error moving dir from " + fileName + ".new to " + fileName;
- printfd(__FILE__, "FILES_STORE::SaveUserConf - rename failed. Message: '%s'\n", strerror(errno));
- return -1;
+ snprintf(userdataName, 12, "Userdata%d", i);
+ cfstat.WriteString(userdataName, conf.userdata[i]);
}
+cfstat.WriteInt("CreditExpire", conf.creditExpire);
+
+stringstream ipStr;
+ipStr << conf.ips;
+cfstat.WriteString("IP", ipStr.str());
return 0;
}
//BAK_FILE bakFile(fileName, storeSettings.GetRemoveBak());
-Touch(fileName + ".new");
-
{
- CONFIGFILE cfstat(fileName + ".new");
+ CONFIGFILE cfstat(fileName, true);
int e = cfstat.Error();
if (e)
cfstat.WriteInt("LastCashAddTime", stat.lastCashAddTime);
cfstat.WriteInt("PassiveTime", stat.passiveTime);
cfstat.WriteInt("LastActivityTime", stat.lastActivityTime);
-
- e = chmod(fileName.c_str(), storeSettings.GetStatMode());
- e += chown(fileName.c_str(), storeSettings.GetStatUID(), storeSettings.GetStatGID());
-
- if (e)
- {
- STG_LOCKER lock(&mutex, __FILE__, __LINE__);
- printfd(__FILE__, "FILES_STORE::SaveUserStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
- }
}
-if (rename((fileName + ".new").c_str(), fileName.c_str()) < 0)
+e = chmod(fileName.c_str(), storeSettings.GetStatMode());
+e += chown(fileName.c_str(), storeSettings.GetStatUID(), storeSettings.GetStatGID());
+
+if (e)
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
- errorStr = "Error moving dir from " + fileName + ".new to " + fileName;
- printfd(__FILE__, "FILES_STORE::SaveUserStat - rename failed. Message: '%s'\n", strerror(errno));
- return -1;
+ printfd(__FILE__, "FILES_STORE::SaveUserStat - chmod/chown failed for user '%s'. Error: '%s'\n", login.c_str(), strerror(errno));
}
return 0;
strprintf(&str,"%s/%s/stat.%d.%02d",
storeSettings.GetUsersDir().c_str(), login.c_str(), year + 1900, month + 1);
-Touch(str);
-
-CONFIGFILE s(str);
+CONFIGFILE s(str, true);
e = s.Error();
if (e)
strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), ac.login.c_str());
-Touch(fileName + ".new");
-
{
- CONFIGFILE cf(fileName + ".new");
+ CONFIGFILE cf(fileName, true);
int e = cf.Error();
pass[ADM_PASSWD_LEN - 1] = 0;
Encode12(passwordE, pass, ADM_PASSWD_LEN);
- //printfd(__FILE__, "passwordE %s\n", passwordE);
cf.WriteString("password", passwordE);
cf.WriteInt("ChgConf", ac.priv.userConf);
cf.WriteInt("ChgAdmin", ac.priv.adminChg);
}
-if (rename((fileName + ".new").c_str(), fileName.c_str()) < 0)
- {
- STG_LOCKER lock(&mutex, __FILE__, __LINE__);
- errorStr = "Error moving dir from " + fileName + ".new to " + fileName;
- printfd(__FILE__, "FILES_STORE::SaveAdmin - rename failed. Message: '%s'\n", strerror(errno));
- return -1;
- }
-
return 0;
}
//-----------------------------------------------------------------------------
{
string fileName = storeSettings.GetTariffsDir() + "/" + tariffName + ".tf";
-Touch(fileName + ".new");
-
{
- CONFIGFILE cf(fileName + ".new");
+ CONFIGFILE cf(fileName, true);
int e = cf.Error();
}
}
-if (rename((fileName + ".new").c_str(), fileName.c_str()) < 0)
- {
- STG_LOCKER lock(&mutex, __FILE__, __LINE__);
- errorStr = "Error moving dir from " + fileName + ".new to " + fileName;
- printfd(__FILE__, "FILES_STORE::SaveTariff - rename failed. Message: '%s'\n", strerror(errno));
- return -1;
- }
-
return 0;
}
//-----------------------------------------------------------------------------