|
|
f70500 |
From 42f5f956c3dbae0151176762a42ce564d603975c Mon Sep 17 00:00:00 2001
|
|
|
f70500 |
From: usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
|
|
|
f70500 |
Date: Wed, 28 Mar 2018 14:34:14 +0000
|
|
|
f70500 |
Subject: [PATCH] merge revision(s) 62990:
|
|
|
f70500 |
|
|
|
f70500 |
Ignore file separator from tmpfile/tmpdir name.
|
|
|
f70500 |
|
|
|
f70500 |
From: SHIBATA Hiroshi <hsbt@ruby-lang.org>
|
|
|
f70500 |
|
|
|
f70500 |
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@63017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
|
|
|
f70500 |
---
|
|
|
f70500 |
lib/tmpdir.rb | 2 ++
|
|
|
f70500 |
test/test_tempfile.rb | 49 ++++++++++++++++++++++++++++++++++++++++++-
|
|
|
f70500 |
test/test_tmpdir.rb | 40 +++++++++++++++++++++++++++++++++++
|
|
|
f70500 |
3 files changed, 90 insertions(+), 1 deletion(-)
|
|
|
f70500 |
|
|
|
f70500 |
diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb
|
|
|
f70500 |
index 18d4fb683d..e483f16602 100644
|
|
|
f70500 |
--- a/lib/tmpdir.rb
|
|
|
f70500 |
+++ b/lib/tmpdir.rb
|
|
|
f70500 |
@@ -116,6 +116,8 @@ class Dir
|
|
|
f70500 |
else
|
|
|
f70500 |
raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
|
|
|
f70500 |
end
|
|
|
f70500 |
+ prefix = prefix.delete("#{File::SEPARATOR}#{File::ALT_SEPARATOR}")
|
|
|
f70500 |
+ suffix &&= suffix.delete("#{File::SEPARATOR}#{File::ALT_SEPARATOR}")
|
|
|
f70500 |
t = Time.now.strftime("%Y%m%d")
|
|
|
f70500 |
path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
|
|
f70500 |
path << "-#{n}" if n
|
|
|
f70500 |
diff --git a/test/test_tempfile.rb b/test/test_tempfile.rb
|
|
|
f70500 |
index 087d9ad31f..b6790a06af 100644
|
|
|
f70500 |
--- a/test/test_tempfile.rb
|
|
|
f70500 |
+++ b/test/test_tempfile.rb
|
|
|
f70500 |
@@ -319,5 +319,52 @@ puts Tempfile.new('foo').path
|
|
|
f70500 |
assert_equal(0600, t.stat.mode & 0777)
|
|
|
f70500 |
end
|
|
|
f70500 |
end
|
|
|
f70500 |
-end
|
|
|
f70500 |
|
|
|
f70500 |
+ def test_create_with_block
|
|
|
f70500 |
+ path = nil
|
|
|
f70500 |
+ Tempfile.create("tempfile-create") {|f|
|
|
|
f70500 |
+ path = f.path
|
|
|
f70500 |
+ assert(File.exist?(path))
|
|
|
f70500 |
+ }
|
|
|
f70500 |
+ assert(!File.exist?(path))
|
|
|
f70500 |
+ end
|
|
|
f70500 |
+
|
|
|
f70500 |
+ def test_create_without_block
|
|
|
f70500 |
+ path = nil
|
|
|
f70500 |
+ f = Tempfile.create("tempfile-create")
|
|
|
f70500 |
+ path = f.path
|
|
|
f70500 |
+ assert(File.exist?(path))
|
|
|
f70500 |
+ f.close
|
|
|
f70500 |
+ assert(File.exist?(path))
|
|
|
f70500 |
+ ensure
|
|
|
f70500 |
+ f.close if f && !f.closed?
|
|
|
f70500 |
+ File.unlink path if path
|
|
|
f70500 |
+ end
|
|
|
f70500 |
+
|
|
|
f70500 |
+ TRAVERSAL_PATH = Array.new(Dir.pwd.split('/').count, '..').join('/') + Dir.pwd + '/'
|
|
|
f70500 |
+
|
|
|
f70500 |
+ def test_open_traversal_dir
|
|
|
f70500 |
+ expect = Dir.glob(TRAVERSAL_PATH + '*').count
|
|
|
f70500 |
+ t = Tempfile.open([TRAVERSAL_PATH, 'foo'])
|
|
|
f70500 |
+ actual = Dir.glob(TRAVERSAL_PATH + '*').count
|
|
|
f70500 |
+ assert_equal expect, actual
|
|
|
f70500 |
+ ensure
|
|
|
f70500 |
+ t.close!
|
|
|
f70500 |
+ end
|
|
|
f70500 |
+
|
|
|
f70500 |
+ def test_new_traversal_dir
|
|
|
f70500 |
+ expect = Dir.glob(TRAVERSAL_PATH + '*').count
|
|
|
f70500 |
+ t = Tempfile.new(TRAVERSAL_PATH + 'foo')
|
|
|
f70500 |
+ actual = Dir.glob(TRAVERSAL_PATH + '*').count
|
|
|
f70500 |
+ assert_equal expect, actual
|
|
|
f70500 |
+ ensure
|
|
|
f70500 |
+ t.close!
|
|
|
f70500 |
+ end
|
|
|
f70500 |
+
|
|
|
f70500 |
+ def test_create_traversal_dir
|
|
|
f70500 |
+ expect = Dir.glob(TRAVERSAL_PATH + '*').count
|
|
|
f70500 |
+ Tempfile.create(TRAVERSAL_PATH + 'foo')
|
|
|
f70500 |
+ actual = Dir.glob(TRAVERSAL_PATH + '*').count
|
|
|
f70500 |
+ assert_equal expect, actual
|
|
|
f70500 |
+ end
|
|
|
f70500 |
+end
|
|
|
f70500 |
diff --git a/test/test_tmpdir.rb b/test/test_tmpdir.rb
|
|
|
f70500 |
index 3bdce3542c..2585453183 100644
|
|
|
f70500 |
--- a/test/test_tmpdir.rb
|
|
|
f70500 |
+++ b/test/test_tmpdir.rb
|
|
|
f70500 |
@@ -30,4 +30,44 @@ class TestTmpdir < Test::Unit::TestCase
|
|
|
f70500 |
ENV["HOME"] = home
|
|
|
f70500 |
Dir.rmdir(dir) if dir
|
|
|
f70500 |
end
|
|
|
f70500 |
+
|
|
|
f70500 |
+ def test_mktmpdir_nil
|
|
|
f70500 |
+ Dir.mktmpdir(nil) {|d|
|
|
|
f70500 |
+ assert_kind_of(String, d)
|
|
|
f70500 |
+ }
|
|
|
f70500 |
+ end
|
|
|
f70500 |
+
|
|
|
f70500 |
+ TRAVERSAL_PATH = Array.new(Dir.pwd.split('/').count, '..').join('/') + Dir.pwd + '/'
|
|
|
f70500 |
+ TRAVERSAL_PATH.delete!(':') if /mswin|mingw/ =~ RUBY_PLATFORM
|
|
|
f70500 |
+
|
|
|
f70500 |
+ def test_mktmpdir_traversal
|
|
|
f70500 |
+ expect = Dir.glob(TRAVERSAL_PATH + '*').count
|
|
|
f70500 |
+ Dir.mktmpdir(TRAVERSAL_PATH + 'foo')
|
|
|
f70500 |
+ actual = Dir.glob(TRAVERSAL_PATH + '*').count
|
|
|
f70500 |
+ assert_equal expect, actual
|
|
|
f70500 |
+ end
|
|
|
f70500 |
+
|
|
|
f70500 |
+ def test_mktmpdir_traversal_array
|
|
|
f70500 |
+ expect = Dir.glob(TRAVERSAL_PATH + '*').count
|
|
|
f70500 |
+ Dir.mktmpdir([TRAVERSAL_PATH, 'foo'])
|
|
|
f70500 |
+ actual = Dir.glob(TRAVERSAL_PATH + '*').count
|
|
|
f70500 |
+ assert_equal expect, actual
|
|
|
f70500 |
+ end
|
|
|
f70500 |
+
|
|
|
f70500 |
+ TRAVERSAL_PATH = Array.new(Dir.pwd.split('/').count, '..').join('/') + Dir.pwd + '/'
|
|
|
f70500 |
+ TRAVERSAL_PATH.delete!(':') if /mswin|mingw/ =~ RUBY_PLATFORM
|
|
|
f70500 |
+
|
|
|
f70500 |
+ def test_mktmpdir_traversal
|
|
|
f70500 |
+ expect = Dir.glob(TRAVERSAL_PATH + '*').count
|
|
|
f70500 |
+ Dir.mktmpdir(TRAVERSAL_PATH + 'foo')
|
|
|
f70500 |
+ actual = Dir.glob(TRAVERSAL_PATH + '*').count
|
|
|
f70500 |
+ assert_equal expect, actual
|
|
|
f70500 |
+end
|
|
|
f70500 |
+
|
|
|
f70500 |
+ def test_mktmpdir_traversal_array
|
|
|
f70500 |
+ expect = Dir.glob(TRAVERSAL_PATH + '*').count
|
|
|
f70500 |
+ Dir.mktmpdir([TRAVERSAL_PATH, 'foo'])
|
|
|
f70500 |
+ actual = Dir.glob(TRAVERSAL_PATH + '*').count
|
|
|
f70500 |
+ assert_equal expect, actual
|
|
|
f70500 |
+ end
|
|
|
f70500 |
end
|
|
|
f70500 |
--
|
|
|
f70500 |
2.17.1
|
|
|
f70500 |
|