nanoc-core 4.11.17 → 4.11.22

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
  SHA256:
3
- metadata.gz: 748b150c5ee93de8c4ce8dcd31ddc4e4dc64897a73d86dd91be9d743b1ff476d
4
- data.tar.gz: '008722ff9d57b3c5e13fda3e5ac60dd4860a1240076383067a37664ebb7df2ca'
3
+ metadata.gz: 01ecf44ca25369ee5a16d3ab97f0d4880da51e5db1a1b15bf75e75eee4eb88da
4
+ data.tar.gz: 9cbeb1d146e6fa525b15cf19c62d39c0fe646c4586fed345689e7d0ae276adbf
5
5
  SHA512:
6
- metadata.gz: 49b011afe4838c9150bd91ccaf17acd7150f5d143af69b13e623f542ff2af7965205f4b2a595b07e651babada9e902a98e2c879f923070be21c14fd199c5674d
7
- data.tar.gz: aefeed726b1ac55565446d4fc7ccce5a3d5293029ad7b0e534e33f8f0ff338d0f7d8f9641dfd964125e5a71dbb243aa95e9cf447d071478fea03d1e2a485ea4c
6
+ metadata.gz: 5de5f16a2b47132155d2a85e3123cf4dc7f43e2c5fdea4d75361fdfbac310093da814b4112ecda5c1c58a5f9f19aefd33457fd260f4c02b1d1b8b46bcefc6c6f
7
+ data.tar.gz: af0216df8261745768e686b040f3b78f1a0efccd6490f7db4c551af1873f5066526a396b0761de3deaf8a84b0b167a39dcebe3b91b244d611788dcc4cf5735c5
@@ -9,6 +9,7 @@ require 'tmpdir'
9
9
  require 'yaml'
10
10
 
11
11
  # External gems
12
+ require 'concurrent-ruby'
12
13
  require 'json_schema'
13
14
  require 'ddmemoize'
14
15
  require 'ddmetrics'
@@ -19,6 +20,13 @@ require 'tomlrb'
19
20
  require 'tty-platform'
20
21
  require 'zeitwerk'
21
22
 
23
+ # External gems (optional)
24
+ begin
25
+ require 'clonefile'
26
+ rescue LoadError
27
+ # ignore
28
+ end
29
+
22
30
  module Nanoc
23
31
  module Core
24
32
  # Similar to `nil` except that it can only be compared against using
@@ -6,45 +6,6 @@ module Nanoc
6
6
  class Write < Abstract
7
7
  include Nanoc::Core::ContractsSupport
8
8
 
9
- class Worker
10
- def initialize(queue:, compiled_content_store:)
11
- @queue = queue
12
- @compiled_content_store = compiled_content_store
13
- end
14
-
15
- def start
16
- @thread = Thread.new do
17
- Thread.current.abort_on_exception = true
18
- Thread.current.priority = -1 # schedule I/O work ASAP
19
-
20
- writer = Nanoc::Core::ItemRepWriter.new
21
-
22
- while rep = @queue.pop # rubocop:disable Lint/AssignmentInCondition
23
- writer.write_all(rep, @compiled_content_store)
24
- end
25
- end
26
- end
27
-
28
- def join
29
- @thread.join
30
- end
31
- end
32
-
33
- class WorkerPool
34
- def initialize(queue:, size:, compiled_content_store:)
35
- @workers = Array.new(size) { Worker.new(queue: queue, compiled_content_store: compiled_content_store) }
36
- end
37
-
38
- def start
39
- @workers.each(&:start)
40
- end
41
-
42
- def join
43
- @workers.each(&:join)
44
- end
45
- end
46
-
47
- QUEUE_SIZE = 40
48
9
  WORKER_POOL_SIZE = 5
49
10
 
50
11
  def initialize(compiled_content_store:, wrapped:)
@@ -52,19 +13,16 @@ module Nanoc
52
13
 
53
14
  @compiled_content_store = compiled_content_store
54
15
 
55
- @queue = SizedQueue.new(QUEUE_SIZE)
56
- @worker_pool = WorkerPool.new(queue: @queue, size: WORKER_POOL_SIZE, compiled_content_store: @compiled_content_store)
57
- end
16
+ @pool = Concurrent::FixedThreadPool.new(WORKER_POOL_SIZE)
58
17
 
59
- def start
60
- super
61
- @worker_pool.start
18
+ @writer = Nanoc::Core::ItemRepWriter.new
62
19
  end
63
20
 
64
21
  def stop
22
+ @pool.shutdown
23
+ @pool.wait_for_termination
24
+
65
25
  super
66
- @queue.close
67
- @worker_pool.join
68
26
  end
69
27
 
70
28
  contract Nanoc::Core::ItemRep, C::KeywordArgs[is_outdated: C::Bool], C::Func[C::None => C::Any] => C::Any
@@ -76,7 +34,9 @@ module Nanoc
76
34
  # notification happens before the :rep_write_enqueued one.
77
35
  Nanoc::Core::NotificationCenter.post(:rep_write_enqueued, rep)
78
36
 
79
- @queue << rep
37
+ @pool.post do
38
+ @writer.write_all(rep, @compiled_content_store)
39
+ end
80
40
  end
81
41
  end
82
42
  end
@@ -96,7 +96,8 @@ module Nanoc
96
96
  false
97
97
  end
98
98
 
99
- @_contracts_support__should_enable = contracts_loadable && !ENV.key?('DISABLE_CONTRACTS')
99
+ # FIXME: Do something better with contracts on Ruby 3.x
100
+ @_contracts_support__should_enable = contracts_loadable && !RUBY_VERSION.start_with?('3') && !ENV.key?('DISABLE_CONTRACTS')
100
101
 
101
102
  if @_contracts_support__should_enable
102
103
  # FIXME: ugly
@@ -62,11 +62,7 @@ module Nanoc
62
62
 
63
63
  # Write
64
64
  if is_modified
65
- begin
66
- FileUtils.ln(temp_path, raw_path, force: true)
67
- rescue Errno::EXDEV, Errno::EACCES
68
- FileUtils.cp(temp_path, raw_path)
69
- end
65
+ smart_cp(temp_path, raw_path)
70
66
  end
71
67
 
72
68
  item_rep.modified = is_modified
@@ -80,6 +76,28 @@ module Nanoc
80
76
  def temp_filename
81
77
  Nanoc::Core::TempFilenameFactory.instance.create(TMP_TEXT_ITEMS_DIR)
82
78
  end
79
+
80
+ def smart_cp(from, to)
81
+ # Try clonefile
82
+ if defined?(Clonefile)
83
+ FileUtils.rm_f(to)
84
+ begin
85
+ res = Clonefile.always(from, to)
86
+ return if res
87
+ rescue Clonefile::UnsupportedPlatform, Errno::ENOTSUP, Errno::EXDEV, Errno::EINVAL
88
+ end
89
+ end
90
+
91
+ # Try with hardlink
92
+ begin
93
+ FileUtils.ln(from, to, force: true)
94
+ return
95
+ rescue Errno::EXDEV, Errno::EACCES
96
+ end
97
+
98
+ # Fall back to old-school copy
99
+ FileUtils.cp(from, to)
100
+ end
83
101
  end
84
102
  end
85
103
  end
@@ -14,6 +14,7 @@ module Nanoc
14
14
  def initialize
15
15
  @counts = {}
16
16
  @root_dir = Dir.mktmpdir('nanoc')
17
+ @mutex = Mutex.new
17
18
  end
18
19
 
19
20
  # @param [String] prefix A string prefix to include in the temporary
@@ -21,8 +22,11 @@ module Nanoc
21
22
  #
22
23
  # @return [String] A new unused filename
23
24
  def create(prefix)
24
- count = @counts.fetch(prefix, 0)
25
- @counts[prefix] = count + 1
25
+ count = nil
26
+ @mutex.synchronize do
27
+ count = @counts.fetch(prefix, 0)
28
+ @counts[prefix] = count + 1
29
+ end
26
30
 
27
31
  dirname = File.join(@root_dir, prefix)
28
32
  filename = File.join(@root_dir, prefix, count.to_s)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Nanoc
4
4
  module Core
5
- VERSION = '4.11.17'
5
+ VERSION = '4.11.22'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.11.17
4
+ version: 4.11.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Defreyne
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-12 00:00:00.000000000 Z
11
+ date: 2021-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: concurrent-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: ddmemoize
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -285,23 +299,23 @@ homepage: https://nanoc.ws/
285
299
  licenses:
286
300
  - MIT
287
301
  metadata: {}
288
- post_install_message:
302
+ post_install_message:
289
303
  rdoc_options: []
290
304
  require_paths:
291
305
  - lib
292
306
  required_ruby_version: !ruby/object:Gem::Requirement
293
307
  requirements:
294
- - - "~>"
308
+ - - ">="
295
309
  - !ruby/object:Gem::Version
296
- version: '2.4'
310
+ version: '2.5'
297
311
  required_rubygems_version: !ruby/object:Gem::Requirement
298
312
  requirements:
299
313
  - - ">="
300
314
  - !ruby/object:Gem::Version
301
315
  version: '0'
302
316
  requirements: []
303
- rubygems_version: 3.1.4
304
- signing_key:
317
+ rubygems_version: 3.2.3
318
+ signing_key:
305
319
  specification_version: 4
306
320
  summary: Core of Nanoc
307
321
  test_files: []