Refactor: only untar once

The code in processImage() execute "tar xf" twice, the first time to
extract the MANIFEST, and the second time to extract the whole tarball.

On a tarball without compression, it's OK. But if the tarball is
compressed, it takes much longer time to de-compress the tarball for
twice.

This commit changes the behavior by:
1. Untar the whole tarball into a temp dir;
2. Parse the manifest as before;
3. If something is wrong, remove the temp dir as before;
4. If it's valid, rename the temp dir to the valid image dir.

It also fixes an issue that it uses const_cast in mkdtemp, which is
undefined behavior because the returned const char* shall be read-only,
writing this memory could cause undefined behavior.

Partially resovles openbmc/bmcweb#60

Tested: Verify the image upload works well, and it takes much less time
        on a gzip compressed tarball.

Change-Id: I0af81acbd948e9c54d5d168c9f72e8ebbf8daebe
Signed-off-by: Lei YU <mine260309@gmail.com>
1 file changed