File tree Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -149,6 +149,23 @@ describe UNIXServer do
149
149
end
150
150
end
151
151
152
+ it " won't delete existing file on bind failure" do
153
+ path = " /tmp/crystal-test-unix.sock"
154
+
155
+ File .write(path, " " )
156
+ File .exists?(path).should be_true
157
+
158
+ begin
159
+ expect_raises Errno , /(already|Address) in use/ do
160
+ UNIXServer .new(path)
161
+ end
162
+
163
+ File .exists?(path).should be_true
164
+ ensure
165
+ File .delete(path) if File .exists?(path)
166
+ end
167
+ end
168
+
152
169
describe " accept" do
153
170
it " returns the client UNIXSocket" do
154
171
UNIXServer .open(" /tmp/crystal-test-unix-sock" ) do |server |
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ class UNIXServer < UNIXSocket
29
29
super (Family ::UNIX , type )
30
30
31
31
bind(UNIXAddress .new(path)) do |error |
32
- close
32
+ close( delete: false )
33
33
raise error
34
34
end
35
35
@@ -65,10 +65,10 @@ class UNIXServer < UNIXSocket
65
65
end
66
66
67
67
# Closes the socket, then deletes the filesystem pathname if it exists.
68
- def close
69
- super
68
+ def close (delete = true )
69
+ super ()
70
70
ensure
71
- if path = @path
71
+ if delete && ( path = @path )
72
72
File .delete(path) if File .exists?(path)
73
73
@path = nil
74
74
end
You can’t perform that action at this time.
0 commit comments