rubysl-tmpdir 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f465ce324da358775919276e049487ae381a03f
4
- data.tar.gz: 99567400b80a6966d0e754e024badae4c2d90e31
3
+ metadata.gz: 3c3738f5ee5f6a9a14c853ec09b92f28184a97dd
4
+ data.tar.gz: 8c3f78e9983f98102141907c09ee4206a156fda6
5
5
  SHA512:
6
- metadata.gz: f916e8bd545ff3f33b616e0127e463a895923c4a860088c15aae2d22eca166a46c03267a6d895fcc0e8428902ab52272c706b7ee5d76ae514ad3bc54f43efde5
7
- data.tar.gz: 1b16af989ad465436379c5f1ad414d5c9e93f334dc016981a2b663ee5a095b34016ff2f034f2451a8e6c22de3b080e31699399c23b397b72e6e25a785f562768
6
+ metadata.gz: 22b02e647848ee6ded4b44391015c7e80559f704d6cff7483facd4f9b6d87947ce667ea48e65ff879c02e85bea02aaf4f71a2d17f5b5171d05a4370848606699
7
+ data.tar.gz: 8be289cc7696602da5218cf3daf4123425435adb8102efe976c388d55da731761c4d2bbbcaf94f5cb9dbf7e2b529ba1b70dde764060971419d22ee9889aa5b06
data/.travis.yml CHANGED
@@ -3,5 +3,5 @@ env:
3
3
  - RUBYLIB=lib
4
4
  script: bundle exec mspec
5
5
  rvm:
6
- - 1.8.7
7
- - rbx-nightly-18mode
6
+ - 1.9.3
7
+ - rbx-nightly-19mode
@@ -1,37 +1,18 @@
1
1
  #
2
2
  # tmpdir - retrieve temporary directory path
3
3
  #
4
- # $Id: tmpdir.rb 21776 2009-01-26 02:12:10Z shyouhei $
4
+ # $Id: tmpdir.rb 28230 2010-06-08 13:14:51Z naruse $
5
5
  #
6
6
 
7
7
  require 'fileutils'
8
+ begin
9
+ require 'etc.so'
10
+ rescue LoadError
11
+ end
8
12
 
9
13
  class Dir
10
14
 
11
- @@systmpdir = '/tmp'
12
-
13
- begin
14
- require 'Win32API'
15
- CSIDL_LOCAL_APPDATA = 0x001c
16
- max_pathlen = 260
17
- windir = "\0"*(max_pathlen+1)
18
- begin
19
- getdir = Win32API.new('shell32', 'SHGetFolderPath', 'LLLLP', 'L')
20
- raise RuntimeError if getdir.call(0, CSIDL_LOCAL_APPDATA, 0, 0, windir) != 0
21
- windir = File.expand_path(windir.rstrip)
22
- rescue RuntimeError
23
- begin
24
- getdir = Win32API.new('kernel32', 'GetSystemWindowsDirectory', 'PL', 'L')
25
- rescue RuntimeError
26
- getdir = Win32API.new('kernel32', 'GetWindowsDirectory', 'PL', 'L')
27
- end
28
- len = getdir.call(windir, windir.size)
29
- windir = File.expand_path(windir[0, len])
30
- end
31
- temp = File.join(windir.untaint, 'temp')
32
- @@systmpdir = temp if File.directory?(temp) and File.writable?(temp)
33
- rescue LoadError
34
- end
15
+ @@systmpdir ||= defined?(Etc.systmpdir) ? Etc.systmpdir : '/tmp'
35
16
 
36
17
  ##
37
18
  # Returns the operating system's temporary file path.
@@ -41,12 +22,11 @@ class Dir
41
22
  if $SAFE > 0
42
23
  tmp = @@systmpdir
43
24
  else
44
- for dir in [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'],
45
- ENV['USERPROFILE'], @@systmpdir, '/tmp']
46
- if dir and File.directory?(dir) and File.writable?(dir)
25
+ for dir in [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp']
26
+ if dir and stat = File.stat(dir) and stat.directory? and stat.writable?
47
27
  tmp = dir
48
28
  break
49
- end
29
+ end rescue nil
50
30
  end
51
31
  File.expand_path(tmp)
52
32
  end
@@ -96,41 +76,67 @@ class Dir
96
76
  # FileUtils.remove_entry_secure dir
97
77
  # end
98
78
  #
99
- def Dir.mktmpdir(prefix_suffix=nil, tmpdir=nil)
100
- case prefix_suffix
101
- when nil
102
- prefix = "d"
103
- suffix = ""
104
- when String
105
- prefix = prefix_suffix
106
- suffix = ""
107
- when Array
108
- prefix = prefix_suffix[0]
109
- suffix = prefix_suffix[1]
79
+ def Dir.mktmpdir(prefix_suffix=nil, *rest)
80
+ path = Tmpname.create(prefix_suffix || "d", *rest) {|n| mkdir(n, 0700)}
81
+ if block_given?
82
+ begin
83
+ yield path
84
+ ensure
85
+ FileUtils.remove_entry_secure path
86
+ end
110
87
  else
111
- raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
88
+ path
112
89
  end
113
- tmpdir ||= Dir.tmpdir
114
- t = Time.now.strftime("%Y%m%d")
115
- n = nil
116
- begin
117
- path = "#{tmpdir}/#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
90
+ end
91
+
92
+ module Tmpname # :nodoc:
93
+ module_function
94
+
95
+ def tmpdir
96
+ Dir.tmpdir
97
+ end
98
+
99
+ def make_tmpname(prefix_suffix, n)
100
+ case prefix_suffix
101
+ when String
102
+ prefix = prefix_suffix
103
+ suffix = ""
104
+ when Array
105
+ prefix = prefix_suffix[0]
106
+ suffix = prefix_suffix[1]
107
+ else
108
+ raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
109
+ end
110
+ t = Time.now.strftime("%Y%m%d")
111
+ path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
118
112
  path << "-#{n}" if n
119
113
  path << suffix
120
- Dir.mkdir(path, 0700)
121
- rescue Errno::EEXIST
122
- n ||= 0
123
- n += 1
124
- retry
125
114
  end
126
115
 
127
- if block_given?
116
+ def create(basename, *rest)
117
+ if opts = Hash.try_convert(rest[-1])
118
+ opts = opts.dup if rest.pop.equal?(opts)
119
+ max_try = opts.delete(:max_try)
120
+ opts = [opts]
121
+ else
122
+ opts = []
123
+ end
124
+ tmpdir, = *rest
125
+ if $SAFE > 0 and tmpdir.tainted?
126
+ tmpdir = '/tmp'
127
+ else
128
+ tmpdir ||= tmpdir()
129
+ end
130
+ n = nil
128
131
  begin
129
- yield path
130
- ensure
131
- FileUtils.remove_entry_secure path
132
+ path = File.expand_path(make_tmpname(basename, n), tmpdir)
133
+ yield(path, n, *opts)
134
+ rescue Errno::EEXIST
135
+ n ||= 0
136
+ n += 1
137
+ retry if !max_try or n < max_try
138
+ raise "cannot generate temporary name using `#{basename}' under `#{tmpdir}'"
132
139
  end
133
- else
134
140
  path
135
141
  end
136
142
  end
@@ -1,5 +1,5 @@
1
1
  module RubySL
2
2
  module Tmpdir
3
- VERSION = "1.0.0"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
@@ -16,6 +16,8 @@ Gem::Specification.new do |spec|
16
16
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
17
  spec.require_paths = ["lib"]
18
18
 
19
+ spec.required_ruby_version = "~> 2.0"
20
+
19
21
  spec.add_development_dependency "bundler", "~> 1.3"
20
22
  spec.add_development_dependency "rake", "~> 10.0"
21
23
  spec.add_development_dependency "mspec", "~> 1.5"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubysl-tmpdir
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Shirai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-27 00:00:00.000000000 Z
11
+ date: 2013-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -82,9 +82,9 @@ require_paths:
82
82
  - lib
83
83
  required_ruby_version: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - '>='
85
+ - - ~>
86
86
  - !ruby/object:Gem::Version
87
- version: '0'
87
+ version: '2.0'
88
88
  required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  requirements:
90
90
  - - '>='