Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

rpg-unpack takes -f (force) and -n (noop) args

  • Loading branch information...
commit d9b675871b68a0e4af44d858a7e09761ad315b3a 1 parent 7ff2ec3
Ryan Tomayko authored

Showing 1 changed file with 20 additions and 5 deletions. Show diff stats Hide diff stats

  1. +20 5 rpg-unpack.sh
25 rpg-unpack.sh
@@ -22,24 +22,30 @@ USAGE '${PROGNAME} [-p <path>|-P] <package> [<version>]
22 22 Unpack a gem file to disk or as a tar stream on standard output.
23 23
24 24 Options
25   - -p <path> Unpack under <path> instead of the working directory.
26   - -P Unpack under RPGPACKS instead of the working directory.
27 25 -c Write gem data tar stream to stdout. Do not create any files.
  26 + -f Unpack over an existing directory.
28 27 -m Change the behavior of the -c option. Write gem metadata
29 28 segment instead of the data segment.
  29 + -n Do nothing if unpack directory already exists.
  30 + -p <path> Unpack under <path> instead of the working directory.
  31 + -P Unpack under RPGPACKS instead of the working directory.
30 32
31 33 The <package> may be a package name or path to a gem file on disk. When a
32 34 package name is given, the <version> may also be specified.'
33 35 workdir=.
34 36 filter=untar
35 37 segment=data.tar.gz
36   -while getopts cmPp: opt
  38 +noop=false
  39 +force=false
  40 +while getopts cfmnPp: opt
37 41 do
38 42 case $opt in
39 43 p) workdir="$OPTARG";;
40 44 P) workdir="$RPGCACHE";;
41 45 c) filter=cat;;
42 46 m) segment=metadata.gz;;
  47 + f) force=true;;
  48 + n) noop=true;;
43 49 ?) helpthem
44 50 exit 2;;
45 51 esac
@@ -71,11 +77,20 @@ version=${basename##*-}
71 77 # newly created directory after the gem name. When the `-c` option is not
72 78 # given, the gem tar stream is piped through here.
73 79 untar () {
74   - mkdir "$workdir/$package-$version"
  80 + if $force
  81 + then mkdir -p "$workdir/$package-$version"
  82 + else mkdir "$workdir/$package-$version"
  83 + fi
75 84 tar -xom -C "$workdir/$package-$version" -f - 2>/dev/null
76 85 }
77 86
78   -notice "$file -> $workdir/$package-$version"
  87 +# Bail out with just the unpack directory on stdout if the -n option was
  88 +# given.
  89 +$noop && test "$filter" = "untar" -a -d "$workdir/$package-$version" && {
  90 + notice "$workdir/$package-$version already exists. noop'ing."
  91 + echo "$workdir/$package-$version"
  92 + exit 0
  93 +}
79 94
80 95 # Pipe the gem directly into `tar` and extract only the file/segment we're
81 96 # interested in (the `-O` option causes the file to be written to stdout

0 comments on commit d9b6758

Please sign in to comment.
Something went wrong with that request. Please try again.