pathname2 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/CHANGES +12 -0
  2. data/MANIFEST +1 -0
  3. data/README +12 -12
  4. data/Rakefile +74 -0
  5. data/lib/pathname2.rb +21 -15
  6. data/test/tc_pathname.rb +11 -19
  7. metadata +3 -2
data/CHANGES CHANGED
@@ -1,3 +1,15 @@
1
+ == 1.5.2 - 9-Mar-2007
2
+ * Bug fix for the Pathname#realpath method where it was not handling recursive
3
+ symlinks. The C version was also fixed, but it only affected platforms that
4
+ don't have the realpath() function.
5
+ * Added a test for recursive symlinks (for Solaris, anyway).
6
+ * Updated the docs for Pathname#realpath.
7
+ * Minor speed enhancements for the C version and the elimination of one
8
+ (potential) segfault.
9
+ * Added a 'Future Plans' section to the README.
10
+ * Added a Rakefile. You can now build, clean, and test and install (both the
11
+ pure Ruby and C versions).
12
+
1
13
  == 1.5.1 - 28-Aug-2006
2
14
  * Added the Kernel#pn method as a shortcut for Pathname.new.
3
15
  * The Pathname#readlink now properly handles symbolic links. The 'fix'
data/MANIFEST CHANGED
@@ -1,5 +1,6 @@
1
1
  CHANGES
2
2
  MANIFEST
3
+ Rakefile
3
4
  README
4
5
  install.rb
5
6
  pathname2.gempsec
data/README CHANGED
@@ -1,5 +1,5 @@
1
1
  == Description
2
- A drop in replacement for the current Pathname class.
2
+ A drop-in replacement for the current Pathname class.
3
3
 
4
4
  == Prerequisites
5
5
  * Ruby 1.8.0 or later
@@ -10,21 +10,16 @@
10
10
 
11
11
  == Installation, pure Ruby
12
12
  === Manual Installation
13
- ruby test/tc_pathname.rb (Unix, optional)
14
- ruby test/tc_pathname_win.rb (Windows, optional)
15
- ruby install.rb
13
+ rake test (optional)
14
+ rake install
16
15
 
17
16
  === Gem Installation
18
- ruby test/tc_pathname.rb (Unix, optional)
19
- ruby test/tc_pathname_win.rb (Windows, optional)
17
+ rake test (optional)
20
18
  gem install pathname2-<version>.gem
21
19
 
22
20
  == Installation, C extension
23
- cd to the 'ext' directory.
24
- ruby extconf.rb
25
- make
26
- run appropriate test (optional)
27
- make install
21
+ rake test_c (optional)
22
+ rake install_c
28
23
 
29
24
  == Synopsis
30
25
  require "pathname2"
@@ -98,9 +93,14 @@
98
93
  Pathname#glob is not yet implemented in the C version.
99
94
  Pathname#find is not implemented properly in the C version.
100
95
 
101
- In Ruby 1.8.3 and later you will see a failure in the test suite regarding
96
+ In Ruby 1.8.3 and 1.8.4 you will see a failure in the test suite regarding
102
97
  'fu_world_writable?' from FileUtils. You can ignore this. That method is
103
98
  supposed to be private. See ruby-core:7383.
99
+
100
+ == Future Plans
101
+ Because ftools is more or less deprecated, and FileUtils can generally do
102
+ everything ftools can do, and better, I'm going to remove ftools in the
103
+ 1.6.0 release.
104
104
 
105
105
  == License
106
106
  Ruby's
data/Rakefile ADDED
@@ -0,0 +1,74 @@
1
+ require 'rake'
2
+ require 'rake/clean'
3
+ require 'rake/testtask'
4
+
5
+ desc "Clean the build files from the pathname2 source"
6
+ task :clean do
7
+ Dir.chdir('ext') do
8
+ if RUBY_PLATFORM.match('mswin')
9
+ sh 'nmake distclean' if File.exists?('pathname2.so')
10
+ else
11
+ sh 'make distclean' if File.exists?('pathname2.so')
12
+ end
13
+ end
14
+ end
15
+
16
+ desc "Build the pathname2 package on UNIX systems (but don't install it)"
17
+ task :build => [:clean] do
18
+ Dir.chdir('ext') do
19
+ ruby 'extconf.rb'
20
+ if RUBY_PLATFORM.match('mswin')
21
+ sh 'nmake'
22
+ else
23
+ sh 'make'
24
+ end
25
+ end
26
+ end
27
+
28
+ desc "Install the pure Ruby version of the pathname2 package"
29
+ task :install do
30
+ cp 'lib/pathname2.rb', Config::CONFIG['sitelibdir']
31
+ end
32
+
33
+ desc "Install the C version of the pathname2 package"
34
+ task :install_c => [:build] do
35
+ Dir.chdir('ext') do
36
+ if RUBY_PLATFORM.match('mswin')
37
+ sh 'nmake install'
38
+ else
39
+ sh 'make install'
40
+ end
41
+ end
42
+ end
43
+
44
+ desc "Run the test suite for the pure Ruby version"
45
+ Rake::TestTask.new('test') do |t|
46
+ t.libs << 'lib'
47
+ if RUBY_PLATFORM.match('mswin')
48
+ t.test_files = FileList['test/tc_pathname_win.rb']
49
+ else
50
+ t.test_files = FileList['test/tc_pathname.rb']
51
+ end
52
+ end
53
+
54
+ desc "Run the test suite for the C version."
55
+ Rake::TestTask.new('test_c') do |t|
56
+ task :test_c => :build
57
+ t.libs << 'ext'
58
+ t.libs.delete('lib')
59
+ if RUBY_PLATFORM.match('mswin')
60
+ t.test_files = FileList['test/tc_pathname_win.rb']
61
+ else
62
+ t.test_files = FileList['test/tc_pathname.rb']
63
+ end
64
+ end
65
+
66
+ desc "Run the benchmark suite for the pure Ruby version"
67
+ task :benchmark do
68
+ sh 'ruby -Ilib examples/bench_pathname.rb'
69
+ end
70
+
71
+ desc "Run the benchmark suite for the C version"
72
+ task :benchmark_c => [:build] do
73
+ sh 'ruby -Iext examples/bench_pathname.rb c'
74
+ end
data/lib/pathname2.rb CHANGED
@@ -57,7 +57,7 @@ class Pathname < String
57
57
  include Windows::File
58
58
  end
59
59
 
60
- VERSION = '1.5.1'
60
+ VERSION = '1.5.2'
61
61
  MAX_PATH = 260
62
62
 
63
63
  # Creates and returns a new Pathname object.
@@ -107,24 +107,21 @@ class Pathname < String
107
107
  # Returns a real (absolute) pathname of +self+ in the actual filesystem.
108
108
  #
109
109
  # Unlike most Pathname methods, this one assumes that the path actually
110
- # exists on your filesystem. If it doesn't, an error is raised.
110
+ # exists on your filesystem. If it doesn't, an error is raised. If a
111
+ # circular symlink is encountered a system error will be raised.
111
112
  #
112
113
  def realpath
113
- File.stat(self) # Check to ensure that the path exists
114
+ File.stat(self) # Check to ensure that the path exists
115
+
114
116
  if File.symlink?(self)
115
- path = self.class.new(File.readlink(self))
116
- if File.symlink?(path)
117
- while File.symlink?(path)
118
- if path.relative?
119
- path = path + File.dirname(path)
120
- else
121
- path = self.class.new(File.readlink(path))
122
- end
123
- end
124
- else
125
- path = self.class.new(File.dirname(self)) + path
117
+ file = self.dup
118
+
119
+ while true
120
+ file = File.join(File.dirname(file), File.readlink(file))
121
+ break unless File.symlink?(file)
126
122
  end
127
- path
123
+
124
+ self.class.new(file).clean
128
125
  else
129
126
  self.class.new(Dir.pwd) + self
130
127
  end
@@ -861,3 +858,12 @@ module Kernel
861
858
  instance_eval{ Pathname.new(yield) }
862
859
  end
863
860
  end
861
+
862
+ if $0 == __FILE__
863
+ path1 = '/dev/fd0'
864
+ path2 = 'link2'
865
+
866
+ path = Pathname.new(path1)
867
+ path = path.realpath
868
+ p path
869
+ end
data/test/tc_pathname.rb CHANGED
@@ -1,24 +1,10 @@
1
1
  ##############################################################################
2
2
  # tc_pathname.rb
3
3
  #
4
- # Test suite for the pathname package (Unix). If you pass a 'c' as command
5
- # line option, it will test against the C extension. Otherwise, it will run
6
- # the tests against the pure Ruby version.
4
+ # Test suite for the pathname package (Unix). This test suite should be run
5
+ # via the Rake tasks, i.e. 'rake test_pr' to test the pure Ruby version, or
6
+ # 'rake test_c' to test the C version.
7
7
  ##############################################################################
8
- Dir.chdir '..' if File.basename(Dir.pwd) == 'test'
9
-
10
- # Test against the C extension if a 'c' is provided as an argument.
11
- if ARGV[0] && ARGV[0].chomp.downcase == 'c'
12
- $LOAD_PATH.unshift Dir.pwd + '/ext'
13
- else
14
- $LOAD_PATH.unshift Dir.pwd + '/lib'
15
- end
16
-
17
- if PLATFORM.match('mswin')
18
- STDERR.puts("Please run 'tc_pathname_win.rb' instead.")
19
- exit
20
- end
21
-
22
8
  require 'pathname2'
23
9
  require 'test/unit'
24
10
 
@@ -77,7 +63,7 @@ class TC_Pathname < Test::Unit::TestCase
77
63
  end
78
64
 
79
65
  def test_version
80
- assert_equal('1.5.1', Pathname::VERSION)
66
+ assert_equal('1.5.2', Pathname::VERSION)
81
67
  end
82
68
 
83
69
  def test_file_url_path
@@ -100,8 +86,13 @@ class TC_Pathname < Test::Unit::TestCase
100
86
  when /sunos|solaris/i
101
87
  path1 = '/dev/null'
102
88
  path2 = '/dev/stdin'
89
+ path3 = '/dev/fd0' # Multiple symlinks
90
+
103
91
  assert_equal('/devices/pseudo/mm@0:null', Pathname.new(path1).realpath)
104
92
  assert_equal('/dev/fd/0', Pathname.new(path2).realpath)
93
+ assert_equal('/devices/pci@1f,0/isa@7/dma@0,0/floppy@0,3f0:c',
94
+ Pathname.new(path3).realpath
95
+ )
105
96
  end
106
97
  end
107
98
 
@@ -231,6 +222,7 @@ class TC_Pathname < Test::Unit::TestCase
231
222
  Dir.pwd + '/CHANGES',
232
223
  Dir.pwd + '/MANIFEST',
233
224
  Dir.pwd + '/README',
225
+ Dir.pwd + '/Rakefile',
234
226
  Dir.pwd + '/examples',
235
227
  Dir.pwd + '/ext',
236
228
  Dir.pwd + '/install.rb',
@@ -249,7 +241,7 @@ class TC_Pathname < Test::Unit::TestCase
249
241
 
250
242
  assert_equal(
251
243
  [
252
- 'CHANGES', 'MANIFEST', 'README', 'examples', 'ext',
244
+ 'CHANGES', 'MANIFEST', 'README', 'Rakefile', 'examples', 'ext',
253
245
  'install.rb', 'lib', 'pathname2.gemspec', 'test'
254
246
  ],
255
247
  children.sort
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: pathname2
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.5.1
7
- date: 2006-08-28 00:00:00 -06:00
6
+ version: 1.5.2
7
+ date: 2007-03-09 00:00:00 -07:00
8
8
  summary: An alternate implementation of the Pathname class
9
9
  require_paths:
10
10
  - lib
@@ -33,6 +33,7 @@ files:
33
33
  - CHANGES
34
34
  - MANIFEST
35
35
  - README
36
+ - Rakefile
36
37
  - test/tc_pathname.rb
37
38
  - test/tc_pathname_win.rb
38
39
  test_files: