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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 70c296f73caebfc4f2f4ab9905e5fd026ab0901c
4
- data.tar.gz: b6b08da8925d1aff26b44d0efa02c629a080ded9
2
+ SHA256:
3
+ metadata.gz: fd8dcc698177728a2089a8ef9bf157d4e1e0d11e59083399b5b0fceecf9b0331
4
+ data.tar.gz: 8ff8321bc0480bc5fe4422c697dceceb0a2743e0a4ac6e35cfc4ef4dab739ee4
5
5
  SHA512:
6
- metadata.gz: f0df7b2ceaeb41f7cb134c7878d5b06a14db34c58612139bf8191bd2a31d0cac85be95ddc7864b69aaafc413f7e9e23ba5cd9570fea5ea3e843742f91c68fb80
7
- data.tar.gz: 0aab39d00f27e5625118698bf0f69fe21bc4df20f4f956743b356708d39ff74201fb19e4eaaed5b2fe3fa843ebc72f902309d2fcad710484f43fc71f3f8c1f04
6
+ metadata.gz: 313f5d0d5ae699228ba5874cc69f72debe1ae7364643e2040d19aa98ae81e874017be52978c576e67478a7bb63ce27170db00f3801dc262b9620778a367f22f1
7
+ data.tar.gz: 040f2c1e8d7bf126feeda45bdf28c6aeba75778f9491afd5d2999e1b15953540e74239ad0d1ca92518ba51ccff030df3ec84175a172609800f6e7a9671f5bb61
@@ -31,18 +31,21 @@ module Sambal
31
31
  options = parsed_options(user_options)
32
32
  @timeout = options[:timeout].to_i
33
33
 
34
- option_flags = "-W \"#{options[:domain]}\" -U \"#{options[:user]}\""
35
- option_flags = "#{option_flags} -I #{options[:ip_address]}" if options[:ip_address]
36
- option_flags = "#{option_flags} -p #{options[:port]} -s /dev/null"
37
- password = options[:password] ? "'#{options[:password]}'" : "--no-pass"
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 + ' ' + option_flags)
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
- exit(1)
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
@@ -1,5 +1,5 @@
1
1
  # coding: UTF-8
2
2
 
3
3
  module Sambal
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
@@ -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.0
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: 2017-09-07 00:00:00.000000000 Z
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.11
69
+ rubygems_version: 2.7.6
70
70
  signing_key:
71
71
  specification_version: 4
72
72
  summary: Ruby Samba Client