Don't blindly reuse state from a previous layer when re-creating it
Don't blindly reuse state from a previous layer when re-creating it

We have reports in the wild of a layer store where two symbolic links
in linkDir point to the same layer. That could only happen when calling
Driver.create with a previously-used layer ID (which happens all the time
because pulls use deterministic layer IDs), without fully deleting
the previous version of the layer (so far, we don't know how that has
happened).

To avoid such situations, don't just leave whatever was in
the layer directory laying around; try to remove any pre-existing
contents, as well as the symbolic link in linkDir, if any.

Signed-off-by: Miloslav Trmač <9c008e38982a5397deb855345fb164f0558459ae@redhat.com>

containers/storage,containers/storage,containers/storage