Skip to content

Commit

Permalink
Stop depending on Set
Browse files Browse the repository at this point in the history
It is now a gem, and since spring load before bundler
if you have multiple `set` versions installed, you might
load the wrong one causing already defined constant warnings.
  • Loading branch information
byroot committed Dec 2, 2021
1 parent fcd8a0f commit 35f03bb
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
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.clonse 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

0 comments on commit 35f03bb

Please sign in to comment.