Fork me on GitHub

#!/usr/bin/env python3
# usage: plash purge [ --yes ]
# Deletes all build data unatomically. Running containers that rely on the
# build data will enter an undefined state. Plashs behaviour while this command
# did not finish running returning an non zero exit code is undefined.

import os
import sys
from shutil import rmtree

from plash.unshare import unshare_if_user
from plash.utils import get_plash_data, handle_help_flag

plash_data = get_plash_data()

if sys.argv[1:2] == ['--yes'] or input('Delete all build data? [y/N] ') == 'y':

    # don't delete the dir itself because it could be a mount

        os.unlink(os.path.join(plash_data, 'id_counter'))
    except FileNotFoundError:

    for dir in os.listdir(plash_data):
        rmtree(os.path.join(plash_data, dir))