metayeti/mINI

When ini.remove(section) is used, ini file breaks

Meridiano opened this issue · 4 comments

Input ini file

[CustomSectionDestroy]
DESTROY_A=WYZ
DESTROY_B=KID

[CustomSectionGet]
iA=123
iB=456
iC=Example String A

[TestPull]
bBool=true
iInt=333
fFloat=135.248
sString=Example String B

[CustomSectionClear]
CLEAR_VALUE_A=ABCD
CLEAR_VALUE_B=EFGH

Output ini file

[CustomSectionGet]
iA=WYZ
iB=KID
iC=123
destroy_a=WYZ
destroy_b=KID

[TestPull]
bBool=123
iInt=456
fFloat=Example String A
sString=true
ia=123
ib=456
ic=Example String A

[CustomSectionClear]
CLEAR_VALUE_A=true
CLEAR_VALUE_B=333
bbool=true
iint=333
ffloat=135.248
sstring=Example String B

Used code snippet > DestroyIniData(1, "mini-test.ini", "CustomSectionDestroy", "") is called

bool DestroyIniData(std::int32_t level, std::string path, std::string section, std::string key) {
	mINI::INIFile file(path);
	mINI::INIStructure ini;
	if (file.read(ini)) {
		if (level == 0) {
			fs::path target = path;
			return std::filesystem::remove(target);
		} else if ((level == 1) && ini.has(section)) {
			ini.remove(section);
			return file.write(ini, usePrettyPrint);
		} else if ((level == 2) && ini.has(section) && ini.get(section).has(key)) {
			ini[section].remove(key);
			return file.write(ini, usePrettyPrint);
		}
		return false;
	}
	return false;
}

I also attach the whole solution (VS 2022), just in case.
mini-test.zip

Version 0.9.14 works as expected, the issue appears only in 0.9.15.

Thanks for reporting this, I'll look into it when I have some time on my hands.

Yeah this is very very bad. Apparently the assignment operator introduced in 0.9.15 is the cause for this, I will publish a new version with a fix soon. Thanks again for reporting this.

Fixed in 0.9.16