...

Source file src/github.com/Microsoft/hcsshim/internal/tools/zapdir/main.go

Documentation: github.com/Microsoft/hcsshim/internal/tools/zapdir

     1  //go:build windows
     2  
     3  package main
     4  
     5  import (
     6  	"context"
     7  	"errors"
     8  	"fmt"
     9  	"os"
    10  	"path/filepath"
    11  
    12  	"github.com/Microsoft/hcsshim/internal/wclayer"
    13  	"github.com/urfave/cli"
    14  )
    15  
    16  const (
    17  	dirArgName = "dir"
    18  )
    19  
    20  func main() {
    21  	app := cli.NewApp()
    22  	app.Name = "zapdir"
    23  	app.Usage = "Delete a directory"
    24  
    25  	app.Flags = []cli.Flag{
    26  		cli.StringFlag{
    27  			Name:  dirArgName,
    28  			Value: "",
    29  			Usage: "Directory to delete",
    30  		},
    31  	}
    32  
    33  	app.Action = func(c *cli.Context) error {
    34  		dir := c.String(dirArgName)
    35  
    36  		if dir == "" {
    37  			return errors.New("dir must be supplied")
    38  		}
    39  
    40  		// DestroyLayer requires an absolute path.
    41  		dir, err := filepath.Abs(dir)
    42  		if err != nil {
    43  			return err
    44  		}
    45  
    46  		if _, err := os.Stat(dir); err != nil {
    47  			return err
    48  		}
    49  
    50  		if err := wclayer.DestroyLayer(context.Background(), dir); err != nil {
    51  			return err
    52  		}
    53  
    54  		return nil
    55  	}
    56  
    57  	err := app.Run(os.Args)
    58  	if err != nil {
    59  		fmt.Fprintln(cli.ErrWriter, err)
    60  		os.Exit(1)
    61  	}
    62  }
    63  

View as plain text