Fork me on GitHub
  ▖     
▃▀▄▄▖▄▄▖
 ▀▖     
        


#!/usr/bin/env python3
#
# usage: plash rm CONTAINER
# Deletes the given container atomically. There are no guarantees of any
# behaviour of running containers whose root file system was deleted.
#
# Parameters may be interpreted as build instruction.

import os
import sys
from shutil import rmtree

from plash.unshare import unshare_if_user
from plash.utils import (die_with_usage, get_plash_data, handle_build_args,
                         handle_help_flag, mkdtemp, nodepath_or_die)

handle_help_flag()
handle_build_args()

try:
    container = sys.argv[1]
except IndexError:
    die_with_usage()

# fs access could need mapped users support
unshare_if_user()

node = nodepath_or_die(container)
tmp = mkdtemp()
os.rename(node, tmp)
rmtree(tmp)