dump_vpd_log: clean up existence checks

Clean up some failure modes for dump_vpd_log. In practice,
this script needs to run set -e as well.  However, rather
than refactor, it would make sense to split out the behavior
either into independent shell scripts (with shunit tests)
or to integrate into a better tested binary (C++).

BUG=chromium:344051
TEST=Verified on Pixel.
* Symlink to a fake file
rm -f /mnt/stateful_partition/unencrypted/cache/vpd/echo/vpd_echo.txt
ln -s /tmp/fake /mnt/stateful_partition/unencrypted/cache/vpd/echo/vpd_echo.txt
rm /home/chronos/.oobe_completed && /usr/sbin/dump_vpd_log
* Expect /mnt/stateful_partition/unencrypted/cache/vpd/echo/vpd_echo.txt
*   is recovered as a plain text and content is correct.
* Expect /var/cache/echo/vpd_echo.txt points to
*   /mnt/stateful_partition/unencrypted/cache/vpd/echo/vpd_echo.txt.
* Expect file and directory permissions are correct.

* On HP Chromebook 11
dump_vpd_log --clean
ln -s /tmp/fake /mnt/stateful_partition/unencrypted/cache/vpd/echo/vpd_echo.txt
rm /home/chronos/.oobe_completed && reboot machine

* Verified VPD works as usual.
* Verified with the file timestamp that cached is not generated for
*   reboot.

Change-Id: Ib4d0aa51feebf5ae95050c0a043c29d8b7212ff4
Signed-off-by: Louis Yung-Chieh Lo <yjlou@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/189433
Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
1 file changed
tree: 4af14846a14497a30600c870644ae062b2db1f5b
  1. include/
  2. lib/
  3. tests/
  4. util/
  5. LICENSE
  6. Makefile
  7. README
  8. vpd.c