ion1-mischacks 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,7 @@
1
+ === 0.0.5 / 2009-06-28
2
+
3
+ * Implement IO#best_datasync, have overwrite use it.
4
+
1
5
  === 0.0.4 / 2009-06-28
2
6
 
3
7
  * Implement overwrite, a method to safely replace a file.
data/README.txt CHANGED
@@ -29,6 +29,9 @@ attempts (default 10) is exceeded.
29
29
  Exception#to_formatted_string:: Returns a string that looks like how Ruby would
30
30
  dump an uncaught exception.
31
31
 
32
+ IO#best_datasync:: Tries fdatasync, falling back to fsync, falling back to
33
+ flush.
34
+
32
35
  == FEATURES/PROBLEMS:
33
36
 
34
37
  The sh method is only safe if your sh script is safe. If unsure, add double
@@ -14,7 +14,7 @@
14
14
  # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
15
 
16
16
  module MiscHacks
17
- VERSION = '0.0.4'
17
+ VERSION = '0.0.5'
18
18
 
19
19
  class ChildError < RuntimeError
20
20
  attr_reader :status
@@ -94,6 +94,8 @@ module MiscHacks
94
94
  begin
95
95
  ret = yield io
96
96
 
97
+ io.best_datasync
98
+
97
99
  File.chmod mode, temppath if mode
98
100
 
99
101
  File.rename temppath, path
@@ -153,4 +155,23 @@ Exception.class_eval do
153
155
  include MiscHacks::ExceptionMixin
154
156
  end
155
157
 
158
+ module MiscHacks
159
+ module IOMixin
160
+ def best_datasync
161
+ meths = [:fdatasync, :fsync, :flush]
162
+
163
+ begin
164
+ send meths.shift
165
+ rescue NoMethodError, NotImplementedError
166
+ retry unless meths.empty?
167
+ raise
168
+ end
169
+ end
170
+ end
171
+ end
172
+
173
+ IO.class_eval do
174
+ include MiscHacks::IOMixin
175
+ end
176
+
156
177
  # vim:set et sw=2 sts=2:
@@ -2,12 +2,12 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{mischacks}
5
- s.version = "0.0.4"
5
+ s.version = "0.0.5"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Johan Kiviniemi"]
9
- s.date = %q{2009-06-28}
10
- s.description = %q{Miscellaneous methods that may or may not be useful. sh:: Safely pass untrusted parameters to sh scripts. fork_and_check:: Run a block in a forked process and raise an exception if the process returns a non-zero value. do_and_exit, do_and_exit!:: Run a block. If the block does not run exit!, a successful exec or equivalent, run exit(1) or exit!(1) ourselves. Useful to make sure a forked block either runs a successful exec or dies. Any exceptions from the block are printed to standard error. overwrite:: Safely replace a file. Writes to a temporary file and then moves it over the old file. tempname_for:: Generates an unique temporary path based on a filename. The generated filename resides in the same directory as the original one. try_n_times:: Retries a block of code until it succeeds or a maximum number of attempts (default 10) is exceeded. Exception#to_formatted_string:: Returns a string that looks like how Ruby would dump an uncaught exception.}
9
+ s.date = %q{2009-07-01}
10
+ s.description = %q{Miscellaneous methods that may or may not be useful. sh:: Safely pass untrusted parameters to sh scripts. fork_and_check:: Run a block in a forked process and raise an exception if the process returns a non-zero value. do_and_exit, do_and_exit!:: Run a block. If the block does not run exit!, a successful exec or equivalent, run exit(1) or exit!(1) ourselves. Useful to make sure a forked block either runs a successful exec or dies. Any exceptions from the block are printed to standard error. overwrite:: Safely replace a file. Writes to a temporary file and then moves it over the old file. tempname_for:: Generates an unique temporary path based on a filename. The generated filename resides in the same directory as the original one. try_n_times:: Retries a block of code until it succeeds or a maximum number of attempts (default 10) is exceeded. Exception#to_formatted_string:: Returns a string that looks like how Ruby would dump an uncaught exception. IO#best_datasync:: Tries fdatasync, falling back to fsync, falling back to flush.}
11
11
  s.email = ["devel@johan.kiviniemi.name"]
12
12
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
13
13
  s.files = ["COPYING", "History.txt", "Manifest.txt", "README.txt", "Rakefile", "lib/mischacks.rb", "mischacks.gemspec", "spec/mischacks_spec.rb", "spec/spec_helper.rb"]
@@ -292,6 +292,30 @@ describe mh do
292
292
  end
293
293
  end
294
294
  end
295
+
296
+ describe 'IOMixin best_datasync' do
297
+ before :all do
298
+ @dir = Dir.mktmpdir
299
+ @file = "#{@dir}/foo"
300
+ @content = "f"
301
+ end
302
+
303
+ after :all do
304
+ FileUtils.rm_rf @dir
305
+ end
306
+
307
+ it 'should at least do a flush' do
308
+ open @file, 'w' do |wio|
309
+ wio << @content
310
+
311
+ File.read(@file).should == ''
312
+
313
+ wio.best_datasync
314
+
315
+ File.read(@file).should == @content
316
+ end
317
+ end
318
+ end
295
319
  end
296
320
 
297
321
  # vim:set et sw=2 sts=2:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ion1-mischacks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johan Kiviniemi
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-28 00:00:00 -07:00
12
+ date: 2009-07-01 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,7 +22,7 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 2.3.1
24
24
  version:
25
- description: "Miscellaneous methods that may or may not be useful. sh:: Safely pass untrusted parameters to sh scripts. fork_and_check:: Run a block in a forked process and raise an exception if the process returns a non-zero value. do_and_exit, do_and_exit!:: Run a block. If the block does not run exit!, a successful exec or equivalent, run exit(1) or exit!(1) ourselves. Useful to make sure a forked block either runs a successful exec or dies. Any exceptions from the block are printed to standard error. overwrite:: Safely replace a file. Writes to a temporary file and then moves it over the old file. tempname_for:: Generates an unique temporary path based on a filename. The generated filename resides in the same directory as the original one. try_n_times:: Retries a block of code until it succeeds or a maximum number of attempts (default 10) is exceeded. Exception#to_formatted_string:: Returns a string that looks like how Ruby would dump an uncaught exception."
25
+ description: "Miscellaneous methods that may or may not be useful. sh:: Safely pass untrusted parameters to sh scripts. fork_and_check:: Run a block in a forked process and raise an exception if the process returns a non-zero value. do_and_exit, do_and_exit!:: Run a block. If the block does not run exit!, a successful exec or equivalent, run exit(1) or exit!(1) ourselves. Useful to make sure a forked block either runs a successful exec or dies. Any exceptions from the block are printed to standard error. overwrite:: Safely replace a file. Writes to a temporary file and then moves it over the old file. tempname_for:: Generates an unique temporary path based on a filename. The generated filename resides in the same directory as the original one. try_n_times:: Retries a block of code until it succeeds or a maximum number of attempts (default 10) is exceeded. Exception#to_formatted_string:: Returns a string that looks like how Ruby would dump an uncaught exception. IO#best_datasync:: Tries fdatasync, falling back to fsync, falling back to flush."
26
26
  email:
27
27
  - devel@johan.kiviniemi.name
28
28
  executables: []