kanrisuru 0.8.17 → 0.8.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kanrisuru/core/find.rb +12 -5
- data/lib/kanrisuru/version.rb +1 -1
- data/spec/functional/core/find_spec.rb +163 -0
- data/spec/unit/core/find_spec.rb +3 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e813c072c86f8c0b076a90d2b8136fb9bc64271df996c6c54c4e2bf6c7b5806
|
4
|
+
data.tar.gz: a763991aa4979eb17c1c0e123d80c2057552b2caf9be24358b39659a292e241d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52be23f3a72de4d6f9633e8b01470949035aec9be4123a87bbfc2e4a93120c463fa1470a69030ad696fbabb389ce60890b64925d129654f513a4baa392846ca8
|
7
|
+
data.tar.gz: 749dfdd773a1256575ab262a73f56be48ec6caaef21e8499ea9fb42d9cb2ae79e569d3f8b9581aa153d9d7031eef88d46c64a9a68900d27e00cf85e28885d45d
|
data/lib/kanrisuru/core/find.rb
CHANGED
@@ -10,6 +10,7 @@ module Kanrisuru
|
|
10
10
|
os_define :linux, :find
|
11
11
|
|
12
12
|
FilePath = Struct.new(:path)
|
13
|
+
REGEX_TYPES = ['emacs', 'posix-awk', 'posix-basic', 'posix-egrep', 'posix-extended']
|
13
14
|
|
14
15
|
def find(opts = {})
|
15
16
|
paths = opts[:paths]
|
@@ -32,7 +33,7 @@ module Kanrisuru
|
|
32
33
|
if paths.instance_of?(Array)
|
33
34
|
paths = paths.join(' ')
|
34
35
|
elsif paths.class != String
|
35
|
-
raise 'Invalid paths type'
|
36
|
+
raise ArgumentError, 'Invalid paths type'
|
36
37
|
end
|
37
38
|
|
38
39
|
command << paths
|
@@ -64,13 +65,19 @@ module Kanrisuru
|
|
64
65
|
command.append_arg('-cmin', opts[:cmin])
|
65
66
|
command.append_arg('-mmin', opts[:mmin])
|
66
67
|
|
67
|
-
|
68
|
+
if Kanrisuru::Util.present?(opts[:regex_type])
|
69
|
+
unless REGEX_TYPES.include?(opts[:regex_type])
|
70
|
+
raise ArgumentError, 'invalid regex type'
|
71
|
+
end
|
68
72
|
|
69
|
-
|
70
|
-
|
73
|
+
command.append_arg('-regextype', opts[:regex_type])
|
74
|
+
end
|
71
75
|
|
72
|
-
|
76
|
+
command.append_arg('-regex', "'#{regex}'") if Kanrisuru::Util.present?(regex)
|
73
77
|
|
78
|
+
if size.instance_of?(String)
|
79
|
+
regex = Regexp.new(/^([-+])?(\d+)([bcwkMG])*$/)
|
80
|
+
raise ArgumentError, "invalid size string: '#{@size}'" unless regex.match?(size)
|
74
81
|
command.append_arg('-size', size)
|
75
82
|
elsif size.instance_of?(Integer)
|
76
83
|
command.append_arg('-size', size)
|
data/lib/kanrisuru/version.rb
CHANGED
@@ -0,0 +1,163 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
StubNetwork.stub!
|
6
|
+
|
7
|
+
RSpec.describe Kanrisuru::Core::Find do
|
8
|
+
let(:host) do
|
9
|
+
Kanrisuru::Remote::Host.new(
|
10
|
+
host: 'localhost',
|
11
|
+
username: 'ubuntu',
|
12
|
+
keys: ['id_rsa']
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'prepares find command' do
|
17
|
+
expect_command(host.find, "find")
|
18
|
+
|
19
|
+
expect_command(host.find(follow: 'never'), "find -P")
|
20
|
+
expect_command(host.find(follow: 'always'), "find -L")
|
21
|
+
expect_command(host.find(follow: 'command'), "find -H")
|
22
|
+
|
23
|
+
expect_command(host.find(paths: '/etc'), "find /etc")
|
24
|
+
expect_command(host.find(paths: ['/etc', '/var', '/home']), "find /etc /var /home")
|
25
|
+
|
26
|
+
expect {
|
27
|
+
host.find(paths: 1)
|
28
|
+
}.to raise_error(ArgumentError)
|
29
|
+
|
30
|
+
expect_command(host.find(paths: '/',
|
31
|
+
executable: true,
|
32
|
+
empty: true,
|
33
|
+
readable: true,
|
34
|
+
writeable: true,
|
35
|
+
nogroup: true,
|
36
|
+
nouser: true,
|
37
|
+
mount: true
|
38
|
+
),
|
39
|
+
"find / -executable -empty -readable -nogroup -nouser -mount"
|
40
|
+
)
|
41
|
+
|
42
|
+
expect_command(host.find(paths: '/',
|
43
|
+
path: "/lib",
|
44
|
+
name: '*.so',
|
45
|
+
gid: 0,
|
46
|
+
uid: 0,
|
47
|
+
user: 'root',
|
48
|
+
group: 'root',
|
49
|
+
links: 2,
|
50
|
+
mindepth: 0,
|
51
|
+
maxdepth: 100
|
52
|
+
),
|
53
|
+
"find / -path /lib -name *.so -gid 0 -uid 0 -user root -group root -links 2 -maxdepth 100 -mindepth 0"
|
54
|
+
)
|
55
|
+
|
56
|
+
expect_command(host.find(paths: '/var/log',
|
57
|
+
atime: '+1',
|
58
|
+
ctime: '+2',
|
59
|
+
mtime: '+3',
|
60
|
+
amin: '100',
|
61
|
+
cmin: '200',
|
62
|
+
mmin: '300'
|
63
|
+
),
|
64
|
+
"find /var/log -atime +1 -ctime +2 -mtime +3 -amin 100 -cmin 200 -mmin 300"
|
65
|
+
)
|
66
|
+
|
67
|
+
expect_command(host.find(
|
68
|
+
paths: '/dev',
|
69
|
+
regex: '/dev/tty[0-9]*'
|
70
|
+
),
|
71
|
+
"find /dev -regex '/dev/tty[0-9]*'"
|
72
|
+
)
|
73
|
+
|
74
|
+
expect_command(host.find(
|
75
|
+
paths: '/dev',
|
76
|
+
regex_type: 'posix-egrep',
|
77
|
+
regex: '/dev/tty[0-9]*'
|
78
|
+
),
|
79
|
+
"find /dev -regextype posix-egrep -regex '/dev/tty[0-9]*'"
|
80
|
+
)
|
81
|
+
|
82
|
+
expect_command(host.find(
|
83
|
+
paths: '/var/log',
|
84
|
+
size: 100
|
85
|
+
),
|
86
|
+
"find /var/log -size 100"
|
87
|
+
)
|
88
|
+
|
89
|
+
expect_command(host.find(
|
90
|
+
paths: '/var/log',
|
91
|
+
size: "100"
|
92
|
+
),
|
93
|
+
"find /var/log -size 100"
|
94
|
+
)
|
95
|
+
|
96
|
+
expect {
|
97
|
+
host.find(size: "100n")
|
98
|
+
}.to raise_error(ArgumentError)
|
99
|
+
|
100
|
+
expect_command(host.find(
|
101
|
+
paths: '/var/log',
|
102
|
+
size: "-100k"
|
103
|
+
),
|
104
|
+
"find /var/log -size -100k"
|
105
|
+
)
|
106
|
+
|
107
|
+
expect_command(host.find(
|
108
|
+
paths: '/var/log',
|
109
|
+
size: "+10M"
|
110
|
+
),
|
111
|
+
"find /var/log -size +10M"
|
112
|
+
)
|
113
|
+
|
114
|
+
expect_command(host.find(
|
115
|
+
paths: "/dev",
|
116
|
+
type: 'directory'
|
117
|
+
),
|
118
|
+
"find /dev -type d"
|
119
|
+
)
|
120
|
+
|
121
|
+
expect_command(host.find(
|
122
|
+
paths: "/dev",
|
123
|
+
type: 'file'
|
124
|
+
),
|
125
|
+
"find /dev -type f"
|
126
|
+
)
|
127
|
+
|
128
|
+
expect_command(host.find(
|
129
|
+
paths: "/dev",
|
130
|
+
type: 'symlinks'
|
131
|
+
),
|
132
|
+
"find /dev -type l"
|
133
|
+
)
|
134
|
+
|
135
|
+
expect_command(host.find(
|
136
|
+
paths: "/dev",
|
137
|
+
type: 'block'
|
138
|
+
),
|
139
|
+
"find /dev -type b"
|
140
|
+
)
|
141
|
+
|
142
|
+
expect_command(host.find(
|
143
|
+
paths: "/dev",
|
144
|
+
type: 'character'
|
145
|
+
),
|
146
|
+
"find /dev -type c"
|
147
|
+
)
|
148
|
+
|
149
|
+
expect_command(host.find(
|
150
|
+
paths: "/dev",
|
151
|
+
type: 'pipe'
|
152
|
+
),
|
153
|
+
"find /dev -type p"
|
154
|
+
)
|
155
|
+
|
156
|
+
expect_command(host.find(
|
157
|
+
paths: "/dev",
|
158
|
+
type: 'socket'
|
159
|
+
),
|
160
|
+
"find /dev -type s"
|
161
|
+
)
|
162
|
+
end
|
163
|
+
end
|
data/spec/unit/core/find_spec.rb
CHANGED
@@ -5,5 +5,8 @@ require 'spec_helper'
|
|
5
5
|
RSpec.describe Kanrisuru::Core::Find do
|
6
6
|
it 'responds to find fields' do
|
7
7
|
expect(Kanrisuru::Core::Find::FilePath.new).to respond_to(:path)
|
8
|
+
expect(Kanrisuru::Core::Find::REGEX_TYPES).to(
|
9
|
+
eq(['emacs', 'posix-awk', 'posix-basic', 'posix-egrep', 'posix-extended'])
|
10
|
+
)
|
8
11
|
end
|
9
12
|
end
|
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.
|
4
|
+
version: 0.8.18
|
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-10-
|
11
|
+
date: 2021-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -173,6 +173,7 @@ files:
|
|
173
173
|
- lib/kanrisuru/util/os_family.rb
|
174
174
|
- lib/kanrisuru/util/signal.rb
|
175
175
|
- lib/kanrisuru/version.rb
|
176
|
+
- spec/functional/core/find_spec.rb
|
176
177
|
- spec/functional/core/path_spec.rb
|
177
178
|
- spec/functional/core/stat_spec.rb
|
178
179
|
- spec/functional/core/stream_spec.rb
|