sambal 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/sambal/client.rb +40 -7
- data/lib/sambal/version.rb +1 -1
- data/spec/sambal/client_spec.rb +11 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fd8dcc698177728a2089a8ef9bf157d4e1e0d11e59083399b5b0fceecf9b0331
|
4
|
+
data.tar.gz: 8ff8321bc0480bc5fe4422c697dceceb0a2743e0a4ac6e35cfc4ef4dab739ee4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 313f5d0d5ae699228ba5874cc69f72debe1ae7364643e2040d19aa98ae81e874017be52978c576e67478a7bb63ce27170db00f3801dc262b9620778a367f22f1
|
7
|
+
data.tar.gz: 040f2c1e8d7bf126feeda45bdf28c6aeba75778f9491afd5d2999e1b15953540e74239ad0d1ca92518ba51ccff030df3ec84175a172609800f6e7a9671f5bb61
|
data/lib/sambal/client.rb
CHANGED
@@ -31,18 +31,21 @@ module Sambal
|
|
31
31
|
options = parsed_options(user_options)
|
32
32
|
@timeout = options[:timeout].to_i
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
password =
|
35
|
+
if options[:authfile]
|
36
|
+
"--authentication-file #{options[:authfile]}"
|
37
|
+
elsif options[:password]
|
38
|
+
options[:password]
|
39
|
+
else
|
40
|
+
'--no-pass'
|
41
|
+
end
|
38
42
|
command = "COLUMNS=#{options[:columns]} smbclient \"//#{options[:host]}/#{options[:share]}\" #{password}"
|
39
43
|
|
40
|
-
@output, @input, @pid = PTY.spawn(command
|
44
|
+
@output, @input, @pid = PTY.spawn("#{command} #{option_flags(options)}")
|
41
45
|
|
42
46
|
res = @output.expect(/(.*\n)?smb:.*\\>/, @timeout)[0] rescue nil
|
43
47
|
@connected = case res
|
44
48
|
when nil
|
45
|
-
$stderr.puts "Failed to connect"
|
46
49
|
false
|
47
50
|
when /^put/
|
48
51
|
res['putting'].nil? ? false : true
|
@@ -58,7 +61,7 @@ module Sambal
|
|
58
61
|
|
59
62
|
unless @connected
|
60
63
|
close if @pid
|
61
|
-
|
64
|
+
raise 'Failed to connect'
|
62
65
|
end
|
63
66
|
rescue => e
|
64
67
|
raise RuntimeError, "Unknown Process Failed!! (#{$!.to_s}): #{e.message.inspect}\n"+e.backtrace.join("\n")
|
@@ -123,6 +126,17 @@ module Sambal
|
|
123
126
|
end
|
124
127
|
end
|
125
128
|
|
129
|
+
def rename(old_filename, new_filename)
|
130
|
+
response = ask_wrapped 'rename', [old_filename, new_filename]
|
131
|
+
if response =~ /renaming\sfile/ # "renaming" reponse only exist if has error
|
132
|
+
Response.new(response, false)
|
133
|
+
else
|
134
|
+
Response.new(response, true)
|
135
|
+
end
|
136
|
+
rescue InternalError => e
|
137
|
+
Response.new(e.message, false)
|
138
|
+
end
|
139
|
+
|
126
140
|
def put(file, destination)
|
127
141
|
response = ask_wrapped 'put', [file, destination]
|
128
142
|
if response =~ /^putting\sfile.*$/
|
@@ -286,5 +300,24 @@ module Sambal
|
|
286
300
|
end
|
287
301
|
Hash[listing.sort]
|
288
302
|
end
|
303
|
+
|
304
|
+
private
|
305
|
+
|
306
|
+
def option_flags(options)
|
307
|
+
flags = []
|
308
|
+
flags << "--workgroup \"#{options[:domain]}\"" if options[:domain] && !options[:authfile]
|
309
|
+
flags << "--user \"#{options[:user]}\"" if options[:user] && !options[:authfile]
|
310
|
+
flags << "--ip-address #{options[:ip_address]}" if options[:ip_address]
|
311
|
+
flags << "--send-buffer #{options[:buffer_size]}" if options[:buffer_size]
|
312
|
+
flags << "--debuglevel #{options[:debug_level]}" if options[:debug_level]
|
313
|
+
flags << '--encrypt' if options[:encrypt]
|
314
|
+
flags << "--max-protocol #{options[:max_protocol]}" if options[:max_protocol]
|
315
|
+
flags << '--use-ccache' if options[:use_ccache]
|
316
|
+
flags << "--socket-options #{options[:socket_options]}" if options[:socket_options]
|
317
|
+
flags << "--port #{options[:port]}" if options[:port]
|
318
|
+
flags << "--name-resolve #{options[:name_resolve]}" if options[:name_resolve]
|
319
|
+
flags << (options[:configfile] ? "--configfile #{options[:configfile]}" : '--configfile /dev/null')
|
320
|
+
flags.join(' ')
|
321
|
+
end
|
289
322
|
end
|
290
323
|
end
|
data/lib/sambal/version.rb
CHANGED
data/spec/sambal/client_spec.rb
CHANGED
@@ -140,6 +140,17 @@ describe Sambal::Client do
|
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
|
+
describe 'rename' do
|
144
|
+
it 'is successful when renaming an existing file' do
|
145
|
+
expect(@sambal_client.rename(TESTFILE, 'renamed_file.txt')).to be_successful
|
146
|
+
expect(File.exists?(File.join(test_server.share_path, 'renamed_file.txt'))).to eq true
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'is unsuccessful when the file does not exist' do
|
150
|
+
expect(@sambal_client.rename('unknown_file.txt', 'renamed_file.txt')).not_to be_successful
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
143
154
|
it "should get files from an smb server" do
|
144
155
|
expect(@sambal_client.get(TESTFILE, "/tmp/sambal_spec_testfile.txt")).to be_successful
|
145
156
|
expect(File.exists?("/tmp/sambal_spec_testfile.txt")).to eq true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sambal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Axel Eriksson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
66
|
version: '0'
|
67
67
|
requirements: []
|
68
68
|
rubyforge_project:
|
69
|
-
rubygems_version: 2.6
|
69
|
+
rubygems_version: 2.7.6
|
70
70
|
signing_key:
|
71
71
|
specification_version: 4
|
72
72
|
summary: Ruby Samba Client
|