Skip to content

Stop depending on Set #659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Next Release

* Stop requiring `set` before bundler can select the proper version. This could result in
`already defined constant` warnings during boot (#659).

## 3.1.1

* Fix compatibility issues with code that raises exceptions with frozen backtraces.
Expand Down
12 changes: 6 additions & 6 deletions lib/spring/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def initialize(manager, original_env, spring_env = Env.new)
@original_env = original_env
@spring_env = spring_env
@mutex = Mutex.new
@waiting = Set.new
@clients = Set.new
@waiting = {}
@clients = {}
@preloaded = false
@state = :initialized
@interrupt = IO.pipe
Expand Down Expand Up @@ -150,7 +150,7 @@ def serve(client)
log "got client"
manager.puts

@clients << client
@clients[client] = true

_stdout, stderr, _stdin = streams = 3.times.map { client.recv_io }
[STDOUT, STDERR, STDIN].zip(streams).each { |a, b| a.reopen(b) }
Expand Down Expand Up @@ -181,7 +181,7 @@ def serve(client)
pid = fork {
# Make sure to close other clients otherwise their graceful termination
# will be impossible due to reference from this fork.
@clients.select { |c| c != client }.each(&:close)
@clients.each_key { |c| c.close if c != client }

Process.setsid
IGNORE_SIGNALS.each { |sig| trap(sig, "DEFAULT") }
Expand Down Expand Up @@ -245,7 +245,7 @@ def terminate
if exiting?
# Ensure that we do not ignore subsequent termination attempts
log "forced exit"
@waiting.each { |pid| Process.kill("TERM", pid) }
@waiting.each_key { |pid| Process.kill("TERM", pid) }
Kernel.exit
else
state! :terminating
Expand Down Expand Up @@ -337,7 +337,7 @@ def reset_streams
end

def wait(pid, streams, client)
@mutex.synchronize { @waiting << pid }
@mutex.synchronize { @waiting[pid] = true }

# Wait in a separate thread so we can run multiple commands at once
Spring.failsafe_thread {
Expand Down
2 changes: 1 addition & 1 deletion lib/spring/client/binstub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def initialize(args)
@mode = :add
@items = args.drop(1)
.map { |name| find_commands name }
.inject(Set.new, :|)
.flatten.uniq
.map { |command| Item.new(command) }
end

Expand Down
2 changes: 1 addition & 1 deletion lib/spring/client/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Spring
module Client
class Rails < Command
COMMANDS = Set.new %w(console runner generate destroy test)
COMMANDS = %w(console runner generate destroy test)

ALIASES = {
"c" => "console",
Expand Down
8 changes: 4 additions & 4 deletions lib/spring/watcher/abstract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def initialize(root, latency)

@root = File.realpath(root)
@latency = latency
@files = Set.new
@directories = Set.new
@files = {}
@directories = {}
@stale = false
@listeners = []

Expand Down Expand Up @@ -63,10 +63,10 @@ def add(*items)
synchronize {
items.each do |item|
if item.directory?
directories << item.realpath.to_s
directories[item.realpath.to_s] = true
else
begin
files << item.realpath.to_s
files[item.realpath.to_s] = true
rescue Errno::ENOENT
# Race condition. Ignore symlinks whose target was removed
# since the check above, or are deeply chained.
Expand Down
2 changes: 1 addition & 1 deletion lib/spring/watcher/polling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def compute_mtime
end

def expanded_files
files + Dir["{#{directories.map { |d| "#{d}/**/*" }.join(",")}}"]
(files.keys + Dir["{#{directories.keys.map { |d| "#{d}/**/*" }.join(",")}}"]).uniq
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions test/support/watcher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ def assert_not_stale
test "add relative path" do
File.write("#{dir}/foo", "foo")
watcher.add "foo"
assert_equal ["#{dir}/foo"], watcher.files.to_a
assert_equal ["#{dir}/foo"], watcher.files.keys
end

test "add dot relative path" do
File.write("#{dir}/foo", "foo")
watcher.add "./foo"
assert_equal ["#{dir}/foo"], watcher.files.to_a
assert_equal ["#{dir}/foo"], watcher.files.keys
end

test "add non existent file" do
Expand All @@ -167,20 +167,20 @@ def assert_not_stale
File.write("#{dir}/foo", "foo")
File.write("#{dir}/bar", "bar")
watcher.add "foo", "bar"
assert_equal ["#{dir}/foo", "#{dir}/bar"], watcher.files.to_a
assert_equal ["#{dir}/foo", "#{dir}/bar"], watcher.files.keys
end

test "add files as nested array" do
File.write("#{dir}/foo", "foo")
watcher.add [["foo"]]
assert_equal ["#{dir}/foo"], watcher.files.to_a
assert_equal ["#{dir}/foo"], watcher.files.keys
end

test "add symlink" do
File.write("#{dir}/bar", "bar")
File.symlink("#{dir}/bar", "#{dir}/foo")
watcher.add './foo'
assert_equal ["#{dir}/bar"], watcher.files.to_a
assert_equal ["#{dir}/bar"], watcher.files.keys
end

test "add dangling symlink" do
Expand Down