sambal 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sambal.rb +69 -29
- data/lib/sambal/version.rb +1 -1
- data/spec/sambal/client_spec.rb +32 -1
- metadata +3 -3
data/lib/sambal.rb
CHANGED
@@ -70,6 +70,24 @@ module Sambal
|
|
70
70
|
raise RuntimeError.exception("Unknown Process Failed!! (#{$!.to_s})")
|
71
71
|
end
|
72
72
|
end
|
73
|
+
|
74
|
+
def file_context(path)
|
75
|
+
if (path_parts = path.split('/')).length>1
|
76
|
+
file = path_parts.pop
|
77
|
+
subdirs = path_parts.length
|
78
|
+
dir = path_parts.join('/')
|
79
|
+
cd dir
|
80
|
+
else
|
81
|
+
file = path
|
82
|
+
end
|
83
|
+
begin
|
84
|
+
yield(file)
|
85
|
+
ensure
|
86
|
+
unless subdirs.nil?
|
87
|
+
subdirs.times { cd '..' }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
73
91
|
|
74
92
|
def ls
|
75
93
|
parse_files(ask("ls"))
|
@@ -84,14 +102,18 @@ module Sambal
|
|
84
102
|
end
|
85
103
|
|
86
104
|
def get(file, output)
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
105
|
+
begin
|
106
|
+
file_context(file) do |file|
|
107
|
+
response = ask "get #{file} #{output}"
|
108
|
+
if response =~ /^getting\sfile.*$/
|
109
|
+
Response.new(response, true)
|
110
|
+
else
|
111
|
+
Response.new(response, false)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
rescue InternalError => e
|
115
|
+
Response.new(e.message, false)
|
92
116
|
end
|
93
|
-
rescue InternalError => e
|
94
|
-
Response.new(e.message, false)
|
95
117
|
end
|
96
118
|
|
97
119
|
def put(file, destination)
|
@@ -123,29 +145,47 @@ module Sambal
|
|
123
145
|
end
|
124
146
|
|
125
147
|
def del(file)
|
126
|
-
|
127
|
-
file
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
Response.new(
|
142
|
-
end
|
143
|
-
rescue InternalError => e
|
144
|
-
Response.new(e.message, false)
|
145
|
-
ensure
|
146
|
-
unless subdirs.nil?
|
147
|
-
subdirs.times { cd '..' }
|
148
|
+
begin
|
149
|
+
file_context(file) do |file|
|
150
|
+
response = ask "del #{file}"
|
151
|
+
next_line = response.split("\n")[1]
|
152
|
+
if next_line =~ /^smb:.*\\>/
|
153
|
+
Response.new(response, true)
|
154
|
+
#elsif next_line =~ /^NT_STATUS_NO_SUCH_FILE.*$/
|
155
|
+
# Response.new(response, false)
|
156
|
+
#elsif next_line =~ /^NT_STATUS_ACCESS_DENIED.*$/
|
157
|
+
# Response.new(response, false)
|
158
|
+
else
|
159
|
+
Response.new(response, false)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
rescue InternalError => e
|
163
|
+
Response.new(e.message, false)
|
148
164
|
end
|
165
|
+
#end
|
166
|
+
#if (path_parts = file.split('/')).length>1
|
167
|
+
# file = path_parts.pop
|
168
|
+
# subdirs = path_parts.length
|
169
|
+
# dir = path_parts.join('/')
|
170
|
+
# cd dir
|
171
|
+
#end
|
172
|
+
# response = ask "del #{file}"
|
173
|
+
# next_line = response.split("\n")[1]
|
174
|
+
# if next_line =~ /^smb:.*\\>/
|
175
|
+
# Response.new(response, true)
|
176
|
+
# #elsif next_line =~ /^NT_STATUS_NO_SUCH_FILE.*$/
|
177
|
+
# # Response.new(response, false)
|
178
|
+
# #elsif next_line =~ /^NT_STATUS_ACCESS_DENIED.*$/
|
179
|
+
# # Response.new(response, false)
|
180
|
+
# else
|
181
|
+
# Response.new(response, false)
|
182
|
+
# end
|
183
|
+
#rescue InternalError => e
|
184
|
+
# Response.new(e.message, false)
|
185
|
+
#ensure
|
186
|
+
# unless subdirs.nil?
|
187
|
+
# subdirs.times { cd '..' }
|
188
|
+
# end
|
149
189
|
end
|
150
190
|
|
151
191
|
def close
|
data/lib/sambal/version.rb
CHANGED
data/spec/sambal/client_spec.rb
CHANGED
@@ -14,8 +14,15 @@ describe Sambal::Client do
|
|
14
14
|
f << "Hello"
|
15
15
|
end
|
16
16
|
FileUtils.mkdir_p "#{test_server.share_path}/#{test_directory}"
|
17
|
+
FileUtils.mkdir_p "#{test_server.share_path}/#{test_directory}/#{test_sub_directory}"
|
18
|
+
File.open("#{test_server.share_path}/#{test_directory}/#{test_sub_directory}/#{testfile_sub}", 'w') do |f|
|
19
|
+
f << "Hello"
|
20
|
+
end
|
21
|
+
FileUtils.chmod 0775, "#{test_server.share_path}/#{test_directory}/#{test_sub_directory}/#{testfile_sub}"
|
22
|
+
FileUtils.chmod 0775, "#{test_server.share_path}/#{test_directory}/#{test_sub_directory}"
|
17
23
|
FileUtils.chmod 0775, "#{test_server.share_path}/#{test_directory}"
|
18
24
|
FileUtils.chmod 0777, "#{test_server.share_path}/#{testfile}"
|
25
|
+
@sambal_client.cd('/')
|
19
26
|
end
|
20
27
|
|
21
28
|
after(:all) do
|
@@ -34,10 +41,26 @@ describe Sambal::Client do
|
|
34
41
|
'testdir'
|
35
42
|
end
|
36
43
|
|
44
|
+
let(:test_sub_directory) do
|
45
|
+
'testdir_sub'
|
46
|
+
end
|
47
|
+
|
48
|
+
let(:sub_directory_path) do
|
49
|
+
"#{test_directory}/#{test_sub_directory}"
|
50
|
+
end
|
51
|
+
|
37
52
|
let(:testfile) do
|
38
53
|
'testfile.txt'
|
39
54
|
end
|
40
55
|
|
56
|
+
let(:testfile_sub) do
|
57
|
+
'testfile_sub.txt'
|
58
|
+
end
|
59
|
+
|
60
|
+
let(:testfile_sub_path) do
|
61
|
+
"#{sub_directory_path}/#{testfile_sub}"
|
62
|
+
end
|
63
|
+
|
41
64
|
it "should list files on an smb server" do
|
42
65
|
@sambal_client.ls.should have_key(testfile)
|
43
66
|
end
|
@@ -48,6 +71,13 @@ describe Sambal::Client do
|
|
48
71
|
File.size("/tmp/sambal_spec_testfile.txt").should == @sambal_client.ls[testfile][:size].to_i
|
49
72
|
end
|
50
73
|
|
74
|
+
it "should get files in a subdirectory while in a higher level directory from an smb server" do
|
75
|
+
@sambal_client.get(testfile_sub_path, "/tmp/sambal_spec_testfile_sub.txt").should be_successful
|
76
|
+
File.exists?("/tmp/sambal_spec_testfile_sub.txt").should == true
|
77
|
+
@sambal_client.cd(sub_directory_path)
|
78
|
+
File.size("/tmp/sambal_spec_testfile_sub.txt").should == @sambal_client.ls[testfile_sub][:size].to_i
|
79
|
+
end
|
80
|
+
|
51
81
|
it "should not be successful when getting a file from an smb server fails" do
|
52
82
|
result = @sambal_client.get("non_existant_file.txt", "/tmp/sambal_spec_non_existant_file.txt")
|
53
83
|
result.should_not be_successful
|
@@ -98,7 +128,8 @@ describe Sambal::Client do
|
|
98
128
|
@sambal_client.put_content("some content", "file_to_delete").should be_successful
|
99
129
|
@sambal_client.cd('/')
|
100
130
|
@sambal_client.del("#{test_directory}/file_to_delete").should be_successful
|
101
|
-
@sambal_client.
|
131
|
+
@sambal_client.cd('/')
|
132
|
+
@sambal_client.ls.should have_key("#{testfile}")
|
102
133
|
end
|
103
134
|
|
104
135
|
it "should not be successful when command fails" do
|
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.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-06-14 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70291248058060 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 2.6.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70291248058060
|
25
25
|
description: Ruby Samba Client using the cmdline smbclient
|
26
26
|
email:
|
27
27
|
- john@insane.se
|