mixlib-archive 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of mixlib-archive might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c0da99947c11bfbad6ca390ab05d7693ded8b13
4
- data.tar.gz: 5001dfe12d40f5c2616a6f758ff99220d1123e09
3
+ metadata.gz: b64bcab7b9f78579acaea734d9a1678db7d542c5
4
+ data.tar.gz: 8116bd9eef7f1748a7cc37e27141d169f3c18426
5
5
  SHA512:
6
- metadata.gz: e65f94017899ce5debd241bfa5e6841bc92cba382f7a81291107939cd3fd14088c41c3f7ff6fa514e1bd57c65fd20267a6f78da0ec2ef249e0be538ca53f33b6
7
- data.tar.gz: 5b62892bd31eeb24c935e6fd28411ca862ede7f3a33ef1e5f449d68c5cda1ccad992ec43c1f4444400ee74fe50f634a1953648a7df1bdec0dd46b15c78db2808
6
+ metadata.gz: e2cc989da54ab896edf43c73b328369ca5190e2a08a21d29c90bf382e1bbabb2d6313aa181cde4c9a28623de88116abd60627b66d3ca6ef3bcf4fd61a9e255f9
7
+ data.tar.gz: 80fa165ebdae08bc5c398e7c06eea5662d3bf9d204ffa0c63636ea53c1172d8b83a3eb7a11164fd0001c9b22c26a573cbb0ad478d5e193035cf98e7a0975ec4e
@@ -1,5 +1,6 @@
1
1
  require "mixlib/archive/tar"
2
2
  require "mixlib/archive/version"
3
+ require "mixlib/log"
3
4
 
4
5
  module Mixlib
5
6
  class Archive
@@ -13,10 +14,16 @@ module Mixlib
13
14
  @extractor = Mixlib::Archive::Tar.new(archive)
14
15
  end
15
16
 
16
- def extract(destination)
17
+ class Log
18
+ extend Mixlib::Log
19
+ end
20
+
21
+ Log.level = :error
22
+
23
+ def extract(destination, perms: true, ignore: [])
17
24
  create_and_empty(destination)
18
25
 
19
- extractor.extract(destination)
26
+ extractor.extract(destination, perms: perms, ignore: ignore)
20
27
  end
21
28
 
22
29
  private
@@ -14,8 +14,14 @@ module Mixlib
14
14
  @options = options
15
15
  end
16
16
 
17
- def extract(destination)
17
+ # Extracts the archive to the given +destination+
18
+ #
19
+ # === Parameters
20
+ # perms<Boolean>:: should the extracter use permissions from the archive.
21
+ # ignore[Array]:: an array of matches of file paths to ignore
22
+ def extract(destination, perms: true, ignore: [])
18
23
  # (http://stackoverflow.com/a/31310593/506908)
24
+ ignore_re = Regexp.union(ignore)
19
25
  reader do |tar|
20
26
  dest = nil
21
27
  tar.each do |entry|
@@ -23,24 +29,31 @@ module Mixlib
23
29
  dest = File.join(destination, entry.read.strip)
24
30
  next
25
31
  end
32
+ next if entry.full_name =~ ignore_re
26
33
  dest ||= File.join(destination, entry.full_name)
27
34
  parent = File.dirname(dest)
28
- FileUtils.mkdir_p(parent, mode: 0755)
35
+ FileUtils.mkdir_p(parent)
29
36
 
30
37
  if entry.directory? || (entry.header.typeflag == "" && entry.full_name.end_with?("/"))
31
38
  File.delete(dest) if File.file?(dest)
32
- FileUtils.mkdir_p(dest, mode: entry.header.mode, verbose: false)
39
+
40
+ if perms
41
+ FileUtils.mkdir_p(dest, mode: entry.header.mode, verbose: false)
42
+ else
43
+ FileUtils.mkdir_p(dest, verbose: false)
44
+ end
45
+
33
46
  elsif entry.file? || (entry.header.typeflag == "" && !entry.full_name.end_with?("/"))
34
47
  FileUtils.rm_rf(dest) if File.directory?(dest)
35
48
  File.open(dest, "wb") do |f|
36
49
  f.print(entry.read)
37
50
  end
38
- FileUtils.chmod(entry.header.mode, dest, verbose: false)
51
+ FileUtils.chmod(entry.header.mode, dest, verbose: false) if perms
39
52
  elsif entry.header.typeflag == "2"
40
53
  # handle symlink
41
54
  File.symlink(entry.header.linkname, dest)
42
55
  else
43
- puts "unknown tar entry: #{entry.full_name} type: #{entry.header.typeflag}"
56
+ Mixlib::Archive::Log.warn "unknown tar entry: #{entry.full_name} type: #{entry.header.typeflag}"
44
57
  end
45
58
 
46
59
  dest = nil
@@ -60,6 +73,7 @@ module Mixlib
60
73
  raw = File.open(archive, "rb")
61
74
 
62
75
  file = if is_gzip_file?(archive)
76
+ Mixlib::Archive::Log.debug "gzip file detected"
63
77
  Zlib::GzipReader.wrap(raw)
64
78
  else
65
79
  raw
@@ -1,5 +1,5 @@
1
1
  module Mixlib
2
2
  class Archive
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "rake", "~> 10.0"
22
22
  spec.add_development_dependency "rspec", "~> 3.0"
23
23
  spec.add_development_dependency "chefstyle"
24
+ spec.add_dependency "mixlib-log"
24
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixlib-archive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef Software, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-13 00:00:00.000000000 Z
11
+ date: 2016-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mixlib-log
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: A simple interface to various archive formats
70
84
  email:
71
85
  - info@chef.io
@@ -104,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
118
  version: '0'
105
119
  requirements: []
106
120
  rubyforge_project:
107
- rubygems_version: 2.5.1
121
+ rubygems_version: 2.4.5.1
108
122
  signing_key:
109
123
  specification_version: 4
110
124
  summary: A simple interface to various archive formats