kanrisuru 0.8.8 → 0.8.12

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
2
  SHA256:
3
- metadata.gz: 389f21ebed2d778e05d949ab651e91e7fd959c4249c32d936355fa1f093802db
4
- data.tar.gz: f83d7f3385b871890a856470a140d6ce2c2efc7ceefdc4f6fe8b9e2f7a454beb
3
+ metadata.gz: 96b168459e76c64aa511a58fc43d0d777d5d783874e47a24c373dd6da2ef3ff4
4
+ data.tar.gz: 461c0236448253694f369cfc1b7757f61aeb0a4e0af3841cea62b6297d862c14
5
5
  SHA512:
6
- metadata.gz: '0185c24a3ff1bdbcc386999f63fb8544a18e8bf9c824e94d001be81785e6a10b7fb47cbcef421399e7e6b1bff805385d5dd4b253b8be7ce2b93fa94022d38596'
7
- data.tar.gz: 74557bd5df7e1d10223a965d6c3e38fa8bed84f77ff4bfb75614abec344fd088299c7b4e92f9fb08b7aad1fa9630ee8c93d208dd40d3a4189ddf157bb048c694
6
+ metadata.gz: 4d8b47306256c698e30c7950fc18a59551fb156b14bc6e077df323a27832af8125f567213ec066ec1c8e5f7295411a0a113823ef4a6c97df0bbf5a6d753fc851
7
+ data.tar.gz: 5152a07e2d3580c4de9fb477d36c8de6f1d3fae3a6e234a6c3a80318524cb8ae6fefaebd984501f63b3b5de79350c2d9b53eac92b133453aebd1c47ba4323619
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## Kanrisuru 0.8.12 (October 3, 20201)
2
+ * Refactor `rmdir` command to only work on empty directories.
3
+
4
+ ## Kanrisuru 0.8.11 (October 1, 20201)
5
+ * Allow `Kanrisuru::Mode` as mode type option in mkdir method.
6
+
7
+ ## Kanrisuru 0.8.10 (August 24, 20201)
8
+ * Fix bug with rspec test case.
9
+
10
+ ## Kanrisuru 0.8.9 (August 24, 2021)
11
+ * Fix spelling error exception `ArgumentError` in `Kanrisuru::Mode` class.
12
+
1
13
  ## Kanrisuru 0.8.8 (August 21, 2021) ##
2
14
  * Add shorthand notation for tar command actions, such as `x` for `extract`, `t` for `list`, and `c` for `create`.
3
15
 
@@ -206,10 +206,19 @@ module Kanrisuru
206
206
  Kanrisuru::Result.new(command)
207
207
  end
208
208
 
209
- def rmdir(path)
210
- return false unless dir?(path)
209
+ def rmdir(paths, opts = {})
210
+ paths = [paths] if paths.instance_of?(String)
211
+ paths.each do |path|
212
+ raise ArgumentError, "Can't delete root path" if path == '/' || realpath(path).path == '/'
213
+ end
214
+
215
+ command = Kanrisuru::Command.new("rmdir #{paths.join(' ')}")
216
+ command.append_flag('--ignore-fail-on-non-empty', opts[:silent])
217
+ command.append_flag('--parents', opts[:parents])
218
+
219
+ execute_shell(command)
211
220
 
212
- rm(path, force: true, recursive: true)
221
+ Kanrisuru::Result.new(command)
213
222
  end
214
223
 
215
224
  def mkdir(path, opts = {})
@@ -219,7 +228,17 @@ module Kanrisuru
219
228
 
220
229
  command = Kanrisuru::Command.new("mkdir #{path}")
221
230
  command.append_flag('-p', opts[:silent])
222
- command.append_arg('-m', opts[:mode])
231
+
232
+ if Kanrisuru::Util.present?(opts[:mode])
233
+ mode = opts[:mode]
234
+ if mode.instance_of?(Kanrisuru::Mode)
235
+ mode = mode.numeric
236
+ elsif mode.instance_of?(String) && (mode.include?(',') || /[=+-]/.match(mode))
237
+ mode = Kanrisuru::Mode.new(mode).numeric
238
+ end
239
+
240
+ command.append_arg('-m', mode)
241
+ end
223
242
 
224
243
  execute_shell(command)
225
244
 
@@ -235,7 +235,7 @@ module Kanrisuru
235
235
  @group = Kanrisuru::Mode::Permission.new(symbolic_to_numeric(modes[3..5]), modes[3..5])
236
236
  @other = Kanrisuru::Mode::Permission.new(symbolic_to_numeric(modes[6..8]), modes[6..8])
237
237
  else
238
- raise ArgumentErorr, "Invalid format for mode #{string}"
238
+ raise ArgumentError, "Invalid format for mode #{string}"
239
239
  end
240
240
  end
241
241
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanrisuru
4
- VERSION = '0.8.8'
4
+ VERSION = '0.8.12'
5
5
  end
@@ -40,8 +40,8 @@ RSpec.describe Kanrisuru::Core::File do
40
40
  keys: [host_json['ssh_key']]
41
41
  )
42
42
 
43
- host.rmdir("#{host_json['home']}/.kanrisuru_spec_files")
44
- host.rmdir("#{host_json['home']}/extract-tar-files") if host.dir?("#{host_json['home']}/extract-tar-files")
43
+ host.rm("#{host_json['home']}/.kanrisuru_spec_files", force: true, recursive: true)
44
+ host.rm("#{host_json['home']}/extract-tar-files", force: true, recursive: true) if host.dir?("#{host_json['home']}/extract-tar-files")
45
45
  host.disconnect
46
46
  end
47
47
 
@@ -67,6 +67,10 @@ RSpec.describe Kanrisuru::Core::File do
67
67
  mode = host.chmod(path, mode).mode
68
68
  expect(mode.symbolic).to eq('-rwxr--r--')
69
69
  expect(mode.to_i).to eq(0o744)
70
+
71
+ expect {
72
+ host.chmod(path, 600)
73
+ }.to raise_error(ArgumentError)
70
74
  end
71
75
 
72
76
  it 'changes file owner and group' do
@@ -318,6 +322,27 @@ RSpec.describe Kanrisuru::Core::File do
318
322
  expect(host.empty_file?(path)).to eq(false)
319
323
  end
320
324
 
325
+ it 'removes directories' do
326
+ result = host.mkdir("#{spec_dir}/directory/1", silent: true)
327
+ expect(result).to be_success
328
+
329
+ result = host.mkdir("#{spec_dir}/directory/2", silent: true)
330
+ expect(result).to be_success
331
+
332
+ result = host.mkdir("#{spec_dir}/directory/3", silent: true)
333
+ expect(result).to be_success
334
+
335
+ result = host.rmdir(["#{spec_dir}/directory/1", "#{spec_dir}/directory/2"])
336
+ expect(result).to be_success
337
+
338
+ ## Can't delete non empty dir
339
+ result = host.rmdir("#{spec_dir}/directory")
340
+ expect(result).to be_failure
341
+
342
+ result = host.rmdir("#{spec_dir}/directory/3")
343
+ expect(result).to be_success
344
+ end
345
+
321
346
  it 'counts a file' do
322
347
  result = host.wc('/etc/hosts')
323
348
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kanrisuru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.8
4
+ version: 0.8.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Mammina
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-22 00:00:00.000000000 Z
11
+ date: 2021-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec