Skip to content

Commit

Permalink
support updating previously corrected folder names
Browse files Browse the repository at this point in the history
  • Loading branch information
sunaku committed Mar 8, 2016
1 parent 605c687 commit 5408885
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 15 additions & 5 deletions bin/dasht-docsets-extract
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
# location specified by the `DASHT_DOCSETS_DIR` environment variable and then
# renames their extracted directories to match their rootnames (sans `.tgz`).
#
# If an extracted directory already exists, its contents are updated in place.
#
# ## ENVIRONMENT
#
# `DASHT_DOCSETS_DIR`
Expand All @@ -52,10 +54,18 @@

test $# -gt 0
for tgz; do
tar -v -C "$DASHT_DOCSETS_DIR" -z -x -f "$tgz" # extract archive
want="$DASHT_DOCSETS_DIR/$(basename "$tgz" .tgz).docset"
have="$DASHT_DOCSETS_DIR/$(tar -z -t -f "$tgz" | head -1 | sed 's,/.*,,')"

# for dasht-docsets-update(1), the extracted directory will already exist
# with the correct name, but we need to temporarily rename it back to the
# wrong name so that the archive extraction below can update its contents
# in place, rather than extracting out to a new (and different) directory
test "$have" = "$want" || test -d "$want" && mv "$want" "$have"

# extract the archive; the extracted directory's path is defined by $have
tar -v -C "$DASHT_DOCSETS_DIR" -z -x -f "$tgz"

# ensure that extracted directory has same rootname as archive
actual="$DASHT_DOCSETS_DIR/$(tar -z -t -f "$tgz" | head -1 | sed 's,/.*,,')"
wanted="$DASHT_DOCSETS_DIR/$(basename "$tgz" .tgz).docset"
test "$actual" = "$wanted" || mv "$actual" "$wanted"
# rename the extracted directory to have the same rootname as the archive
test "$have" = "$want" || mv "$have" "$want"
done
2 changes: 2 additions & 0 deletions man/man1/dasht-docsets-extract.1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ located in a subdirectory one level above the current working directory.
Extracts the given Dash \[la]https://kapeli.com/dash\[ra] docset archive \fIFILE\fPs (\fB\fC*.tgz\fR files) into the
location specified by the \fB\fCDASHT_DOCSETS_DIR\fR environment variable and then
renames their extracted directories to match their rootnames (sans \fB\fC\&.tgz\fR).
.PP
If an extracted directory already exists, its contents are updated in place.
.SH ENVIRONMENT
.TP
\fB\fCDASHT_DOCSETS_DIR\fR
Expand Down

0 comments on commit 5408885

Please sign in to comment.