util/nvmutil: move write checks to writeGbe

doing it in main() is messy. better do it from the
actual function. now the logic in main is clearer.

Signed-off-by: Leah Rowe <leah@libreboot.org>
master
Leah Rowe 2025-01-26 08:52:26 +00:00
parent b01995d167
commit 47d7283462
1 changed files with 6 additions and 3 deletions

View File

@ -147,10 +147,10 @@ main(int argc, char *argv[])
err_if((errno = (cmd == NULL) ? EINVAL : errno)); /* bad user arg */
readGbe(); /* read gbe file into memory */
(*cmd)(); /* operate on gbe file in memory, as per user command */
if ((gbeFileChanged) && (flags != O_RDONLY))
writeGbe();
(*cmd)(); /* operate on gbe file in memory */
writeGbe(); /* write changes back to file */
err_if((errno != 0) && (cmd != cmd_dump)); /* don't err on dump */
return errno; /* errno can be set by the dump command */
@ -413,6 +413,9 @@ goodChecksum(int partnum)
void
writeGbe(void)
{
if ((!gbeFileChanged) || (flags == O_RDONLY))
return;
for (int p = 0; p < 2; p++) {
if ((!nvmPartChanged[p]))
continue;