File tree Expand file tree Collapse file tree 2 files changed +12
-12
lines changed
lib/puppet/module_tool/tar
spec/unit/module_tool/tar Expand file tree Collapse file tree 2 files changed +12
-12
lines changed Original file line number Diff line number Diff line change 4
4
5
5
class Puppet ::ModuleTool ::Tar ::Gnu
6
6
def unpack ( sourcefile , destdir , owner )
7
- sourcefile = File . expand_path ( sourcefile )
7
+ safe_sourcefile = Shellwords . shellescape ( File . expand_path ( sourcefile ) )
8
8
destdir = File . expand_path ( destdir )
9
+ safe_destdir = Shellwords . shellescape ( destdir )
9
10
10
- Dir . chdir ( destdir ) do
11
- Puppet ::Util ::Execution . execute ( "gzip -dc #{ Shellwords . shellescape ( sourcefile ) } | tar xof -" )
12
- Puppet ::Util ::Execution . execute ( "find . -type d -exec chmod 755 {} +" )
13
- Puppet ::Util ::Execution . execute ( "find . -type f -exec chmod u+rw,g+r,a-st {} +" )
14
- Puppet ::Util ::Execution . execute ( "chown -R #{ owner } ." )
15
- end
11
+ Puppet ::Util ::Execution . execute ( "gzip -dc #{ safe_sourcefile } | tar --extract --no-same-owner --directory #{ safe_destdir } --file -" )
12
+ Puppet ::Util ::Execution . execute ( "find #{ safe_destdir } -type d -exec chmod 755 {} +" )
13
+ Puppet ::Util ::Execution . execute ( "find #{ safe_destdir } -type f -exec chmod u+rw,g+r,a-st {} +" )
14
+ Puppet ::Util ::Execution . execute ( "chown -R #{ owner } #{ safe_destdir } " )
16
15
end
17
16
18
17
def pack ( sourcedir , destfile )
Original file line number Diff line number Diff line change 7
7
let ( :sourcedir ) { '/space path/the/src/dir' }
8
8
let ( :destfile ) { '/space path/the/dest/file.tar.gz' }
9
9
10
+ let ( :safe_sourcefile ) { '/space\ path/the/module.tar.gz' }
11
+ let ( :safe_destdir ) { '/space\ path/the/dest/dir' }
10
12
it "unpacks a tar file" do
11
- expect ( Dir ) . to receive ( :chdir ) . with ( File . expand_path ( destdir ) ) . and_yield
12
- expect ( Puppet ::Util ::Execution ) . to receive ( :execute ) . with ( "gzip -dc #{ Shellwords . shellescape ( File . expand_path ( sourcefile ) ) } | tar xof -" )
13
- expect ( Puppet ::Util ::Execution ) . to receive ( :execute ) . with ( "find . -type d -exec chmod 755 {} +" )
14
- expect ( Puppet ::Util ::Execution ) . to receive ( :execute ) . with ( "find . -type f -exec chmod u+rw,g+r,a-st {} +" )
15
- expect ( Puppet ::Util ::Execution ) . to receive ( :execute ) . with ( "chown -R <owner:group> ." )
13
+ expect ( Puppet ::Util ::Execution ) . to receive ( :execute ) . with ( "gzip -dc #{ safe_sourcefile } | tar --extract --no-same-owner --directory #{ safe_destdir } --file -" )
14
+ expect ( Puppet ::Util ::Execution ) . to receive ( :execute ) . with ( "find #{ safe_destdir } -type d -exec chmod 755 {} +" )
15
+ expect ( Puppet ::Util ::Execution ) . to receive ( :execute ) . with ( "find #{ safe_destdir } -type f -exec chmod u+rw,g+r,a-st {} +" )
16
+ expect ( Puppet ::Util ::Execution ) . to receive ( :execute ) . with ( "chown -R <owner:group> #{ safe_destdir } " )
16
17
subject . unpack ( sourcefile , destdir , '<owner:group>' )
17
18
end
18
19
You can’t perform that action at this time.
0 commit comments