bootsnap 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3725f53309883dce83894e47eedbb4d8322eabd5
4
- data.tar.gz: 81e14b1d48fc4431f6ac9bb2729cfb4a69aa0f5c
3
+ metadata.gz: 7c6a61ff4456f0b745e1872ed315eef0d9a644c7
4
+ data.tar.gz: 0515f1b08b95f0d88fb32829f6c99a07494af996
5
5
  SHA512:
6
- metadata.gz: 5a2b45cb55ceffdb5751561b3a35c476ea29bcd3d3a2a68a46521240d35cc1e61cf9ac90265db751b09967655969c7a685725878b5f80a61fd38a0efd7024458
7
- data.tar.gz: 7f7975023cb1856d5ccada63e8be2e3ab94a751d4b80121821f2b01df6cbb94f5172041020ebb9300b63760da3fc2776e3b9b56160b95b4b0c07f82fbce07860
6
+ metadata.gz: 4ce3ba2a352a495e8d8f421ca404273013fcf5ee524e224086e78c4fc106de7505e703481f664fb11068735ead27e4e4b606dc1a67c17fc138b6bf58bcf11c58
7
+ data.tar.gz: fb992465d5f226f6f2d26ecf7491db4d41c4061a3e0742d9991f202c9c7db209a13e4ec40e5fe9f210e4c5119ada8e1b56637f764b55ef4640d655c91587eb1e
@@ -1,3 +1,9 @@
1
+ # 0.3.1
2
+
3
+ * Don't whitelist paths under `RbConfig::CONFIG['prefix']` as stable; instead use `['libdir']` (#41).
4
+ * Catch `EOFError` when reading load-path-cache and regenerate cache.
5
+ * Support relative paths in load-path-cache.
6
+
1
7
  # 0.3.0
2
8
 
3
9
  * Migrate CompileCache from xattr as a cache backend to a cache directory
@@ -46,7 +46,7 @@ module Bootsnap
46
46
  # Try to resolve this feature to an absolute path without traversing the
47
47
  # loadpath.
48
48
  def find(feature)
49
- reinitialize if stale?
49
+ reinitialize if dir_changed? || stale?
50
50
  feature = feature.to_s
51
51
  return feature if feature.start_with?(SLASH)
52
52
  return File.expand_path(feature) if feature.start_with?('./')
@@ -116,6 +116,16 @@ module Bootsnap
116
116
 
117
117
  private
118
118
 
119
+ def dir_changed?
120
+ @prev_dir ||= Dir.pwd
121
+ if @prev_dir == Dir.pwd
122
+ false
123
+ else
124
+ @prev_dir = Dir.pwd
125
+ true
126
+ end
127
+ end
128
+
119
129
  def push_paths_locked(*paths)
120
130
  @store.transaction do
121
131
  paths.map(&:to_s).each do |path|
@@ -124,7 +134,7 @@ module Bootsnap
124
134
  entries, dirs = p.entries_and_dirs(@store)
125
135
  # push -> low precedence -> set only if unset
126
136
  dirs.each { |dir| @dirs[dir] ||= true }
127
- entries.each { |rel| @index[rel] ||= path }
137
+ entries.each { |rel| @index[rel] ||= p.expanded_path }
128
138
  end
129
139
  end
130
140
  end
@@ -137,7 +147,7 @@ module Bootsnap
137
147
  entries, dirs = p.entries_and_dirs(@store)
138
148
  # unshift -> high precedence -> unconditional set
139
149
  dirs.each { |dir| @dirs[dir] = true }
140
- entries.each { |rel| @index[rel] = path }
150
+ entries.each { |rel| @index[rel] = p.expanded_path }
141
151
  end
142
152
  end
143
153
  end
@@ -30,34 +30,42 @@ module Bootsnap
30
30
  false
31
31
  end
32
32
 
33
+ def relative?
34
+ !path.start_with?(SLASH)
35
+ end
36
+
33
37
  # Return a list of all the requirable files and all of the subdirectories
34
38
  # of this +Path+.
35
39
  def entries_and_dirs(store)
36
40
  if stable?
37
41
  # the cached_mtime field is unused for 'stable' paths, but is
38
42
  # set to zero anyway, just in case we change the stability heuristics.
39
- _, entries, dirs = store.get(path)
43
+ _, entries, dirs = store.get(expanded_path)
40
44
  return [entries, dirs] if entries # cache hit
41
45
  entries, dirs = scan!
42
- store.set(path, [0, entries, dirs])
46
+ store.set(expanded_path, [0, entries, dirs])
43
47
  return [entries, dirs]
44
48
  end
45
49
 
46
- cached_mtime, entries, dirs = store.get(path)
50
+ cached_mtime, entries, dirs = store.get(expanded_path)
47
51
 
48
- current_mtime = latest_mtime(path, dirs || [])
52
+ current_mtime = latest_mtime(expanded_path, dirs || [])
49
53
  return [[], []] if current_mtime == -1 # path does not exist
50
54
  return [entries, dirs] if cached_mtime == current_mtime
51
55
 
52
56
  entries, dirs = scan!
53
- store.set(path, [current_mtime, entries, dirs])
57
+ store.set(expanded_path, [current_mtime, entries, dirs])
54
58
  [entries, dirs]
55
59
  end
56
60
 
61
+ def expanded_path
62
+ File.expand_path(path)
63
+ end
64
+
57
65
  private
58
66
 
59
67
  def scan! # (expensive) returns [entries, dirs]
60
- PathScanner.call(path)
68
+ PathScanner.call(expanded_path)
61
69
  end
62
70
 
63
71
  # last time a directory was modified in this subtree. +dirs+ should be a
@@ -83,15 +91,15 @@ module Bootsnap
83
91
  VOLATILE = :volatile
84
92
 
85
93
  # Built-in ruby lib stuff doesn't change, but things can occasionally be
86
- # installed into sitedir, which often lives under prefix.
87
- RUBY_PREFIX = RbConfig::CONFIG['prefix']
88
- SITE_DIR = RbConfig::CONFIG['sitedir']
94
+ # installed into sitedir, which generally lives under libdir.
95
+ RUBY_LIBDIR = RbConfig::CONFIG['libdir']
96
+ RUBY_SITEDIR = RbConfig::CONFIG['sitedir']
89
97
 
90
98
  def stability
91
99
  @stability ||= begin
92
- if Gem.path.detect { |p| path.start_with?(p.to_s) }
100
+ if Gem.path.detect { |p| expanded_path.start_with?(p.to_s) }
93
101
  STABLE
94
- elsif path.start_with?(RUBY_PREFIX) && !path.start_with?(SITE_DIR)
102
+ elsif expanded_path.start_with?(RUBY_LIBDIR) && !expanded_path.start_with?(RUBY_SITEDIR)
95
103
  STABLE
96
104
  else
97
105
  VOLATILE
@@ -3,8 +3,6 @@ require_relative '../load_path_cache'
3
3
  module Bootsnap
4
4
  module LoadPathCache
5
5
  module PathScanner
6
- RelativePathNotSupported = Class.new(StandardError)
7
-
8
6
  REQUIRABLES_AND_DIRS = "/**/*{#{DOT_RB},#{DL_EXTENSIONS.join(',')},/}"
9
7
  IS_DIR = %r{(.*)/\z}
10
8
  NORMALIZE_NATIVE_EXTENSIONS = !DL_EXTENSIONS.include?(LoadPathCache::DOT_SO)
@@ -13,7 +11,6 @@ module Bootsnap
13
11
 
14
12
  def self.call(path)
15
13
  path = path.to_s
16
- raise RelativePathNotSupported unless path.start_with?(SLASH)
17
14
 
18
15
  relative_slice = (path.size + 1)..-1
19
16
  # If the bundle path is a descendent of this path, we do additional
@@ -59,7 +59,7 @@ module Bootsnap
59
59
  @data = begin
60
60
  MessagePack.load(File.binread(@store_path))
61
61
  # handle malformed data due to upgrade incompatability
62
- rescue Errno::ENOENT, MessagePack::MalformedFormatError, MessagePack::UnknownExtTypeError
62
+ rescue Errno::ENOENT, MessagePack::MalformedFormatError, MessagePack::UnknownExtTypeError, EOFError
63
63
  {}
64
64
  end
65
65
  end
@@ -1,3 +1,3 @@
1
1
  module Bootsnap
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootsnap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burke Libbey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-26 00:00:00.000000000 Z
11
+ date: 2017-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler