Set .layout_version to 2 only if it is lower

This commit is contained in:
Vojtech Bocek
2014-10-21 19:55:46 +02:00
parent d6fa2885ea
commit 74ecf0bbf2

View File

@@ -1360,15 +1360,28 @@ int multirom_create_media_link(void)
if(api_level >= 17)
{
FILE *f = fopen(LAYOUT_VERSION, "w");
if(!f)
char buf[16];
buf[0] = 0;
FILE *f = fopen(LAYOUT_VERSION, "r");
const int rewrite = (!f || !fgets(buf, sizeof(buf), f) || atoi(buf) < 2);
if(f)
fclose(f);
if(rewrite)
{
ERROR("Failed to create .layout_version!\n");
return -1;
f = fopen(LAYOUT_VERSION, "w");
if(!f)
{
ERROR("Failed to create .layout_version!\n");
return -1;
}
fputc('2', f);
fclose(f);
chmod(LAYOUT_VERSION, 0600);
}
fputs("2", f);
fclose(f);
chmod(LAYOUT_VERSION, 0600);
}
return 0;