ptools 1.1.5 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ == 1.1.6 - 31-Aug-2007
2
+ * Fixed the File.touch method so that it doesn't whack existing files. Thanks
3
+ go to Thomas Preymesser for the spot.
4
+ * Added corresponding tests to the tc_touch.rb file.
5
+
1
6
  == 1.1.5 - 19-Jul-2007
2
7
  * Added the File.image? method. Inspired by ruby-talk: 260487.
3
8
 
@@ -1,7 +1,7 @@
1
1
  require 'win32/file' if RUBY_PLATFORM.match('mswin')
2
2
 
3
3
  class File
4
- PTOOLS_VERSION = '1.1.5'
4
+ PTOOLS_VERSION = '1.1.6'
5
5
 
6
6
  # :stopdoc:
7
7
 
@@ -243,10 +243,16 @@ class File
243
243
  self
244
244
  end
245
245
 
246
- # Creates the 0 byte file +filename+.
246
+ # Changes the access and modification time if present, or creates a 0
247
+ # byte file +filename+ if it doesn't already exist.
247
248
  #
248
249
  def self.touch(filename)
249
- File.open(filename, 'w'){}
250
+ if File.exists?(filename)
251
+ time = Time.now
252
+ File.utime(time, time, filename)
253
+ else
254
+ File.open(filename, 'w'){}
255
+ end
250
256
  self
251
257
  end
252
258
 
@@ -9,7 +9,7 @@ require 'ptools'
9
9
 
10
10
  class TC_Constants < Test::Unit::TestCase
11
11
  def test_version
12
- assert_equal('1.1.5', File::PTOOLS_VERSION)
12
+ assert_equal('1.1.6', File::PTOOLS_VERSION)
13
13
  end
14
14
 
15
15
  def test_image_ext
@@ -10,7 +10,8 @@ require 'ptools'
10
10
  class TC_FileTouch < Test::Unit::TestCase
11
11
  def setup
12
12
  Dir.chdir('test') unless File.basename(Dir.pwd) == 'test'
13
- @test_file = "delete.this"
13
+ @test_file = 'delete.this'
14
+ @xfile = 'test_file1.txt'
14
15
  end
15
16
 
16
17
  def test_touch_basic
@@ -24,6 +25,14 @@ class TC_FileTouch < Test::Unit::TestCase
24
25
  assert_equal(0, File.size(@test_file))
25
26
  end
26
27
 
28
+ def test_touch_existing_file
29
+ stat = File.stat(@xfile)
30
+ sleep 1
31
+ assert_nothing_raised{ File.touch(@xfile) }
32
+ assert_equal(true, File.size(@xfile) == stat.size)
33
+ assert_equal(false, File.mtime(@xfile) == stat.mtime)
34
+ end
35
+
27
36
  def test_touch_expected_errors
28
37
  assert_raises(ArgumentError){ File.touch }
29
38
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: ptools
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.1.5
7
- date: 2007-07-19 00:00:00 -06:00
6
+ version: 1.1.6
7
+ date: 2007-08-31 00:00:00 -06:00
8
8
  summary: Extra methods for the File class
9
9
  require_paths:
10
10
  - lib