Skip to content

Commit

Permalink
bugfix in handling relative ZIP file paths, so we don't create the ar…
Browse files Browse the repository at this point in the history
…chive inside of the temporary (and later: erased) directory
  • Loading branch information
dirtyhawk committed Feb 24, 2022
1 parent 382122b commit 8bc13ca
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
24 changes: 18 additions & 6 deletions zippkg.ado
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*-------------------------------------------------------------------------------
zippkg.ado: Stata module to create ZIP archives of community-contributed content for offline distribution
Copyright (C) 2019 Daniel Bela (daniel.bela@lifbi.de)
Copyright (C) 2019-2022 Daniel Bela (daniel.bela@lifbi.de)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -19,6 +19,7 @@
-------------------------------------------------------------------------------*/
*! zippkg.ado: Stata module to create ZIP archives of community-contributed content for offline distribution
*! Daniel Bela (daniel.bela@lifbi.de), Leibniz Institute for Educational Trajectories (LIfBi), Germany
*! version 1.1 24 February 2022 - bugfix in handling relative ZIP file paths, so we don't create the archive inside of the temporary (and later: erased) directory
*! version 1.0 26 March 2019 - initialized development version release
program define zippkg , nclass
// version requirements (and string functions dependent on Stata version)
Expand Down Expand Up @@ -74,8 +75,8 @@ program define zippkg , nclass
}
}
}
if (missing(`"`glob_saving'"')) local glob_saving `"./zippkg.zip"'
if (!missing(`"`single'"')) local glob_saving ./zippkg\`speccounter'.zip
if (missing(`"`glob_saving'"')) local glob_saving `"zippkg.zip"'
if (!missing(`"`single'"')) local glob_saving `"zippkg\`speccounter'.zip"'
if (missing(`"`glob_from'"')) local glob_from `"ssc"'
// parse pkgspecs
local speccounter 0
Expand Down Expand Up @@ -151,10 +152,14 @@ program define zippkg , nclass
}
}
// create archive
capture : noisily _zipdir `"`tmppath'"' , saving(`"`savename'"') `targetarchive`targetarchivecounter'_zipopts' `verbose'
local oldpwd `"`c(pwd)'"'
_make_absolute_path `"`savename'"'
local savename_path `s(absolute_path)'
capture : noisily _zipdir `"`tmppath'"' , saving(`"`savename_path'"') `targetarchive`targetarchivecounter'_zipopts' `verbose'
if (_rc!=0) {
display as error in smcl `"creating ZIP archive file {input:`savename'} failed!"'
if (`"`verbose'"'==`"verbose"') display as error in smcl `"{tab}used syntax was: {input}_zipdir `"`tmppath'"' , saving(`"`savename'"') `targetarchive`targetarchivecounter'_zipopts' `verbose'"'
quietly : cd `"`oldpwd'"'
display as error in smcl `"creating ZIP archive file {input:`savename_path'} failed!"'
if (`"`verbose'"'==`"verbose"') display as error in smcl `"{tab}used syntax was: {input}_zipdir `"`tmppath'"' , saving(`"`savename_path'"') `targetarchive`targetarchivecounter'_zipopts' `verbose'"'
}
// clean up
if (`"`verbose'"'==`"verbose"') display as result in smcl `"{tab}{text}...erasing temporary directory {result:`tmppath'}"'
Expand Down Expand Up @@ -257,4 +262,11 @@ program define _create_tempsubdir , sclass
sreturn local tempdirfullpath `"`parent'/`subdirname'"'
exit 0
end
/* subroutine: convert a given, possibly relative, filepath to an absolute filepath */
program define _make_absolute_path , sclass
syntax anything(everything name=dirname id="directory name")
local dirname `dirname'
mata: st_local("absolute_path",pathresolve(`"`c(pwd)'"',`"`dirname'"'))
sreturn local absolute_path `"`absolute_path'"'
end
// EOF
2 changes: 1 addition & 1 deletion zippkg.pkg
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ d KW: net
d
d Requires: Stata version 11 or newer
d
d Distribution-Date: 20190326
d Distribution-Date: 20220224
d
d Author: Daniel Bela
d Support: {browse "https://github.com/dirtyhawk/stata-zippkg"}
Expand Down
4 changes: 2 additions & 2 deletions zippkg.sthlp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{smcl}
{* *! version 1.0 26 March 2019}{...}
{* *! version 1.1 24 February 2022}{...}
{vieweralsosee "[R] net" "help net"}{...}
{vieweralsosee "[R] ssc" "help ssc"}{...}
{vieweralsosee "[D] checksum" "help checksum"}{...}
Expand All @@ -14,7 +14,7 @@
{viewerjumpto "Examples" "zippkg##examples"}{...}
{viewerjumpto "Author" "zippkg##author"}{...}
{viewerjumpto "Also see" "zippkg##alsosee"}{...}
help for {cmd:zippkg}{right:version 1.0 (26 March 2019)}
help for {cmd:zippkg}{right:version 1.1 (24 February 2022)}
{hline}


Expand Down

0 comments on commit 8bc13ca

Please sign in to comment.