dump_vpd_log: clean up existence checks (stabilize-5116.115.B)

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.

Original-Change-Id: Ib4d0aa51feebf5ae95050c0a043c29d8b7212ff4
Signed-off-by: Louis Yung-Chieh Lo <yjlou@chromium.org>
(cherry picked from commit 3abe391c57d063decc389d0777249cd05c0c8e51)

Change-Id: I35cf321784cbe6a16e182030b7ef70af3a6b7e86
Reviewed-on: https://chromium-review.googlesource.com/189755
Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org>
Commit-Queue: Yung-chieh Lo <yjlou@chromium.org>
Tested-by: Yung-chieh Lo <yjlou@chromium.org>
1 file changed
tree: e9dcecc86cae50bd06e2ce22e8aadcceaef3daea
  1. include/
  2. lib/
  3. tests/
  4. util/
  5. LICENSE
  6. Makefile
  7. README
  8. vpd.c