sugar_utils 0.4.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -3
- data/CHANGELOG.md +5 -0
- data/lib/sugar_utils/file.rb +29 -13
- data/lib/sugar_utils/version.rb +1 -1
- data/spec/sugar_utils/file_spec.rb +12 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f9d52c1492ed959f2b33c945732bf36188e6fc1
|
4
|
+
data.tar.gz: b68e7a45954e73eeac4cfe214c5aec54e4602fd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdf2c594969a6c7c0b5279032c18a40b4ce4b6c2b27e86cd814e4f7aa15ded81d661d63890795c5414e27907eb2a4d95c903a22ce3f76803b2f63b41e55bd60b
|
7
|
+
data.tar.gz: 5434657b56c88ee11296ff25d9ee00e43207050da6345f6df4e34717edcb8fbe7bb7dcc492c1cad326cd85efd9fae02f37fe4fd71a7dfffe7162ed9930b5b96e
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.5.0] - 2018-05-01
|
10
|
+
### Changed
|
11
|
+
- bring back :perm as option to set the permissions in SugarUtils::File.write and SugarUtils::File.touch methods
|
12
|
+
- :mode option in SugarUtils::File.write is now to be used for setting the file mode (e.g. read/write, append, etc). It can still be used for setting the permissions if it is an integer value for backwards compatibility purposes, but this usage has been deprecated.
|
13
|
+
|
9
14
|
## [0.4.4] - 2018-01-31
|
10
15
|
### Changed
|
11
16
|
- fixed a bug in SugarUtils::File.read_json which it would raise an exception
|
data/lib/sugar_utils/file.rb
CHANGED
@@ -105,23 +105,26 @@ module SugarUtils
|
|
105
105
|
# @param [Hash] options
|
106
106
|
# @option options [String, Integer] :owner
|
107
107
|
# @option options [String, Integer] :group
|
108
|
-
# @option options [Integer] :mode
|
109
|
-
# @option options [Integer] :perm
|
108
|
+
# @option options [Integer] :mode @deprecated
|
109
|
+
# @option options [Integer] :perm
|
110
110
|
# @option options [Integer] :mtime
|
111
111
|
#
|
112
112
|
# @return [void]
|
113
113
|
def self.touch(filename, options = {})
|
114
114
|
owner = options[:owner]
|
115
115
|
group = options[:group]
|
116
|
-
|
116
|
+
perm = options[:perm]
|
117
117
|
touch_options = options.select { |k| %i[mtime].include?(k) }
|
118
118
|
|
119
|
-
|
119
|
+
if options[:mode].is_a?(Integer)
|
120
|
+
perm = options[:mode]
|
121
|
+
deprecate_option(:touch, :mode, :perm, 2018, 7)
|
122
|
+
end
|
120
123
|
|
121
124
|
FileUtils.mkdir_p(::File.dirname(filename))
|
122
125
|
FileUtils.touch(filename, touch_options)
|
123
126
|
FileUtils.chown(owner, group, filename)
|
124
|
-
FileUtils.chmod(
|
127
|
+
FileUtils.chmod(perm, filename) if perm
|
125
128
|
end
|
126
129
|
|
127
130
|
# @param [String] filename
|
@@ -131,8 +134,8 @@ module SugarUtils
|
|
131
134
|
# @option options [Boolean] :flush (false)
|
132
135
|
# @option options [String, Integer] :owner
|
133
136
|
# @option options [String, Integer] :group
|
134
|
-
# @option options [
|
135
|
-
# @option options [Integer] :perm (0o644)
|
137
|
+
# @option options [String] :mode (w+)
|
138
|
+
# @option options [Integer] :perm (0o644)
|
136
139
|
#
|
137
140
|
# @raise [SugarUtils::File::Error]
|
138
141
|
#
|
@@ -141,15 +144,21 @@ module SugarUtils
|
|
141
144
|
flush = options[:flush] || false
|
142
145
|
owner = options[:owner]
|
143
146
|
group = options[:group]
|
144
|
-
|
147
|
+
perm = options[:perm] || 0o644
|
148
|
+
mode = 'w+'
|
149
|
+
|
150
|
+
if options[:mode].is_a?(Integer)
|
151
|
+
perm = options[:mode]
|
145
152
|
|
146
|
-
|
153
|
+
deprecate_option(:write, :mode, ' with an integer value; use perm instead', 2018, 7)
|
154
|
+
elsif !options[:mode].nil?
|
155
|
+
mode = options[:mode]
|
156
|
+
end
|
147
157
|
|
148
158
|
FileUtils.mkdir_p(::File.dirname(filename))
|
149
|
-
::File.open(filename,
|
159
|
+
::File.open(filename, mode, perm) do |file|
|
150
160
|
flock_exclusive(file, options)
|
151
161
|
|
152
|
-
file.truncate(0) # Ensure file is empty before proceeding.
|
153
162
|
file.puts(data.to_s)
|
154
163
|
|
155
164
|
# Flush and fsync to be 100% sure we write this data out now because we
|
@@ -162,7 +171,7 @@ module SugarUtils
|
|
162
171
|
end
|
163
172
|
|
164
173
|
# Ensure that the permissions are correct if the file already existed.
|
165
|
-
file.chmod(
|
174
|
+
file.chmod(perm)
|
166
175
|
end
|
167
176
|
FileUtils.chown(owner, group, filename)
|
168
177
|
rescue Timeout::Error
|
@@ -205,7 +214,14 @@ module SugarUtils
|
|
205
214
|
|
206
215
|
msg = [
|
207
216
|
"NOTE: #{target}#{method} option :#{option_name} is deprecated",
|
208
|
-
|
217
|
+
case option_repl
|
218
|
+
when :none
|
219
|
+
' with no replacement'
|
220
|
+
when String
|
221
|
+
option_repl
|
222
|
+
else
|
223
|
+
"; use :#{option_repl} instead"
|
224
|
+
end,
|
209
225
|
format('. It will be removed on or after %4d-%02d-01.', year, month),
|
210
226
|
"\n#{target}#{method} called from #{location_of_external_caller}"
|
211
227
|
]
|
data/lib/sugar_utils/version.rb
CHANGED
@@ -171,7 +171,7 @@ describe SugarUtils::File do
|
|
171
171
|
end
|
172
172
|
|
173
173
|
context 'with deprecated options' do
|
174
|
-
let(:options) { {
|
174
|
+
let(:options) { { mode: 0o600 } }
|
175
175
|
before { subject }
|
176
176
|
specify { expect(filename).to have_content(data) }
|
177
177
|
specify { expect(filename).to have_file_permission(0o100600) }
|
@@ -179,7 +179,7 @@ describe SugarUtils::File do
|
|
179
179
|
|
180
180
|
context 'without deprecated options' do
|
181
181
|
let(:options) do
|
182
|
-
{ flush: true, owner: 'nobody', group: 'nogroup', mode: 0o600 }
|
182
|
+
{ flush: true, owner: 'nobody', group: 'nogroup', mode: 'w', perm: 0o600 }
|
183
183
|
end
|
184
184
|
before do
|
185
185
|
expect_any_instance_of(File).to receive(:flush)
|
@@ -201,6 +201,16 @@ describe SugarUtils::File do
|
|
201
201
|
before { write(filename, 'foobar', 0o777) }
|
202
202
|
context 'not locked' do
|
203
203
|
it_behaves_like 'file is written'
|
204
|
+
|
205
|
+
context 'with append mode' do
|
206
|
+
let(:options) { { mode: 'a+' } }
|
207
|
+
before do
|
208
|
+
expect(described_class).to receive(:flock_exclusive)
|
209
|
+
.with(kind_of(File), options)
|
210
|
+
subject
|
211
|
+
end
|
212
|
+
specify { expect(filename).to have_content("foobar#{data}") }
|
213
|
+
end
|
204
214
|
end
|
205
215
|
end
|
206
216
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sugar_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Sullivan Cant
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01
|
11
|
+
date: 2018-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|