sambal 0.0.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/sambal/test_server.rb +3 -1
- data/lib/sambal/version.rb +1 -1
- data/lib/sambal.rb +32 -0
- data/spec/sambal/client_spec.rb +15 -0
- metadata +2 -2
data/lib/sambal/test_server.rb
CHANGED
@@ -38,6 +38,8 @@ module Sambal
|
|
38
38
|
@share_path = "#{root_path}/share"
|
39
39
|
@share_name = share_name
|
40
40
|
@config_path = "#{root_path}/smb.conf"
|
41
|
+
@lock_path = "#{root_path}"
|
42
|
+
@pid_dir = "#{root_path}"
|
41
43
|
@port = Random.new(Time.now.to_i).rand(2345..5678).to_i
|
42
44
|
@run_as = run_as
|
43
45
|
FileUtils.mkdir_p @share_path
|
@@ -57,7 +59,7 @@ module Sambal
|
|
57
59
|
|
58
60
|
def start
|
59
61
|
@smb_server_pid = fork do
|
60
|
-
`smbd -S -F -s #{@config_path} -p #{@port}`
|
62
|
+
`smbd -S -F -s #{@config_path} -p #{@port} --lockdir=#{@lock_path} --piddir=#{@pid_dir}`
|
61
63
|
end
|
62
64
|
sleep 2 ## takes a short time to start up
|
63
65
|
end
|
data/lib/sambal/version.rb
CHANGED
data/lib/sambal.rb
CHANGED
@@ -74,6 +74,14 @@ module Sambal
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
+
def logger
|
78
|
+
@logger ||= Logger.new(STDOUT)
|
79
|
+
end
|
80
|
+
|
81
|
+
def logger=(l)
|
82
|
+
@logger = l
|
83
|
+
end
|
84
|
+
|
77
85
|
def file_context(path)
|
78
86
|
if (path_parts = path.split('/')).length>1
|
79
87
|
file = path_parts.pop
|
@@ -146,6 +154,30 @@ module Sambal
|
|
146
154
|
ensure
|
147
155
|
t.close
|
148
156
|
end
|
157
|
+
|
158
|
+
def rmdir(dir)
|
159
|
+
cd dir
|
160
|
+
begin
|
161
|
+
ls.each do |name, meta|
|
162
|
+
if meta[:type]==:file
|
163
|
+
response = del name
|
164
|
+
elsif meta[:type]==:directory && !(name =~ /^\.+$/)
|
165
|
+
response = rmdir(name)
|
166
|
+
end
|
167
|
+
raise InternalError.new response.message if response && response.failure?
|
168
|
+
end
|
169
|
+
cd '..'
|
170
|
+
response = ask_wrapped 'rmdir', dir
|
171
|
+
next_line = response.split("\n")[1]
|
172
|
+
if next_line =~ /^smb:.*\\>/
|
173
|
+
Response.new(response, true)
|
174
|
+
else
|
175
|
+
Response.new(response, false)
|
176
|
+
end
|
177
|
+
rescue InternalError => e
|
178
|
+
Response.new(e.message, false)
|
179
|
+
end
|
180
|
+
end
|
149
181
|
|
150
182
|
def del(file)
|
151
183
|
begin
|
data/spec/sambal/client_spec.rb
CHANGED
@@ -157,6 +157,21 @@ describe Sambal::Client do
|
|
157
157
|
@sambal_client.ls.should have_key("#{testfile}")
|
158
158
|
end
|
159
159
|
|
160
|
+
it "should recursively delete a directory" do
|
161
|
+
@sambal_client.cd('/')
|
162
|
+
@sambal_client.cd(test_directory)
|
163
|
+
@sambal_client.put_content("some content", "file_to_delete").should be_successful
|
164
|
+
@sambal_client.cd('/')
|
165
|
+
@sambal_client.rmdir("#{test_directory}").should be_successful
|
166
|
+
@sambal_client.cd('/')
|
167
|
+
@sambal_client.ls.should_not have_key("#{test_directory}")
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should not be successful when recursively deleting a nonexistant directory" do
|
171
|
+
@sambal_client.cd('/')
|
172
|
+
@sambal_client.rmdir("this_doesnt_exist").should_not be_successful
|
173
|
+
end
|
174
|
+
|
160
175
|
it "should not be successful when command fails" do
|
161
176
|
result = @sambal_client.put("jhfahsf iasifasifh", "jsfijsf ijidjag")
|
162
177
|
result.should_not be_successful
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sambal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|