about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2012-06-05 17:49:43 -0700
committerEric Wong <normalperson@yhbt.net>2012-06-05 17:49:43 -0700
commitbd7236fe23c4388d2fa42a4f836aca3c796dabab (patch)
tree68c40ff04e15853d12138d06a34dbb73a3e1389b
parent15dea14dd4e1af97aef928430c3c8ef8c5d74451 (diff)
downloadraindrops-bd7236fe23c4388d2fa42a4f836aca3c796dabab.tar.gz
Teach unix_listener_stats to remember the symlink path
it followed and have it point to the same object as the
resolved (real) socket path.

This allows the case where looking up stats by symlinks
works if the symlink is given to unix_listener_stats:

  File.symlink("/real/path/of.sock", "/path/to/link.sock")
  stats = unix_listener_stats(["/path/to/link.sock"])
  stats["/path/to/link.sock"] => # same as stats["/real/path/of.sock"]
-rw-r--r--lib/raindrops/linux.rb9
-rw-r--r--test/test_linux.rb20
2 files changed, 18 insertions, 11 deletions
diff --git a/lib/raindrops/linux.rb b/lib/raindrops/linux.rb
index a198253..1752b8a 100644
--- a/lib/raindrops/linux.rb
+++ b/lib/raindrops/linux.rb
@@ -43,9 +43,14 @@ module Raindrops::Linux
     else
       paths = paths.map do |path|
         path = path.dup
-        path = Pathname.new(path).realpath.to_s
         path.force_encoding(Encoding::BINARY) if defined?(Encoding)
-        rv[path]
+        if File.symlink?(path)
+          link = path
+          path = Pathname.new(link).realpath.to_s
+          rv[link] = rv[path] # vivify ListenerStats
+        else
+          rv[path] # vivify ListenerStats
+        end
         Regexp.escape(path)
       end
     end
diff --git a/test/test_linux.rb b/test/test_linux.rb
index 81463c9..a84eecf 100644
--- a/test/test_linux.rb
+++ b/test/test_linux.rb
@@ -73,24 +73,26 @@ class TestLinux < Test::Unit::TestCase
     us = UNIXServer.new(tmp.path)
 
     # Create a symlink
-    destination = Tempfile.new("somethingelse")
-    destination.unlink # We need an available name, not an actual file
-    link = File.symlink(tmp, destination)
+    link = Tempfile.new("somethingelse")
+    File.unlink(link.path) # We need an available name, not an actual file
+    File.symlink(tmp.path, link.path)
 
     @to_close << UNIXSocket.new(tmp.path)
     stats = unix_listener_stats
-    assert_equal 0, stats[link.path].active
-    assert_equal 1, stats[link.path].queued
+    assert_equal 0, stats[tmp.path].active
+    assert_equal 1, stats[tmp.path].queued
 
-    @to_close << UNIXSocket.new(tmp.path)
-    stats = unix_listener_stats
+    @to_close << UNIXSocket.new(link.path)
+    stats = unix_listener_stats([link.path])
     assert_equal 0, stats[link.path].active
     assert_equal 2, stats[link.path].queued
 
+    assert_equal stats[link.path].object_id, stats[tmp.path].object_id
+
     @to_close << us.accept
     stats = unix_listener_stats
-    assert_equal 1, stats[link.path].active
-    assert_equal 1, stats[link.path].queued
+    assert_equal 1, stats[tmp.path].active
+    assert_equal 1, stats[tmp.path].queued
   end
 
   def test_tcp