Skip to content

Commit

Permalink
Initial implementation of import from archive #14
Browse files Browse the repository at this point in the history
If source is .tar.gz a temp directory is created and the content of the archive are extracted into it. The temp directory is then passed on as the source directory to operate on. On exit the temp directory is removed via an EXIT trap
  • Loading branch information
fxstein committed Oct 23, 2022
1 parent 169e329 commit b4824cf
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion goprox
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,14 @@ libraryopt=""
processopt=""
copyrightopt=""
geonamesopt=""
firmwareopt==""
firmwareopt=""
exiftoolstatus=0
validlibrary=false
validarchive=false
validimported=false
validprocessed=false
validdeleted=false
tempdir=""

function _debug()
{
Expand Down Expand Up @@ -983,6 +984,36 @@ _debug "LibraryOpt: $libraryopt"
_debug "CopyrightOpt: $copyrightopt"
_debug "GeonamesOpt: $geonamesopt"

# Check if source is a tar.gz file
_sourcetype="${sourceopt#*.}"
_debug "Source type: $_sourcetype"

case $_sourcetype in
tar.gz)
# This is a gziped tar ball
_info "Source is $_sourcetype"

# Need to uncompress into a temp directory to proceed
tempdir=`mktemp -d /tmp/${__this__}.XXXXXX` || {
_error "Unable to create temp dir: $tempdir"
exit 1
}
# Make sure it gets removed on exit
trap 'rm -rf -- "$tempdir"' EXIT

_info "Temp dir: $tempdir"

tar -xvf ${sourceopt} -C $tempdir || {
# Archive extraction failed
_error "Archive extraction failed!"
exit 1
}

# Now make temp dir the source of processing
sourceopt=$tempdir
;;
esac

# Now override any parameters that were specified
if [[ -n $sourceopt ]]; then
source=$sourceopt
Expand Down

0 comments on commit b4824cf

Please sign in to comment.