tmpdir 0.1.3 → 0.3.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
  SHA256:
3
- metadata.gz: 23db0dc38a62002db3cbbe9dc185ba6d39a571ff12c064552d62162a511ae280
4
- data.tar.gz: a44a1139f82880434057a5206b73efbfcd7ddce39e6ebb5ae9b69d47d028f20a
3
+ metadata.gz: 1180516b6bd6658a8a32cfefe017af10eb41ed5fa78312d7dd27163b032f1632
4
+ data.tar.gz: d7d4ebda12343e82d2fbfb1f750597692df607672bad6d3134637f94679a96b6
5
5
  SHA512:
6
- metadata.gz: 276895513eab16fa4e2ab9d78216f62b5438cf3a59d24e3be758dd64934bdd86db570590b41bb73480ae699781b2a2e1f36504ae4b34141f8503bca0d6c20001
7
- data.tar.gz: bff0818e6786cdc7b5084f57d4f3b270192fc850aced926fc0a41c40fb50d4d8a18397515c486fe7a73f8838dd8b1594dfda806ae3dd8fc50391c224bd7ab026
6
+ metadata.gz: 965aed93f89f7553bc5c780176119d397aa0b32a203b6f8913806a4e8925887cbe1f0cae96e073547cdf6f102a9c0b2d475fb323097ae9ec3e4e0bba63ba85ff
7
+ data.tar.gz: a48a3973178e8047b1aa139660f2808811e739e6aef1825c316093c1da9c85b8248290a125e0e2f9cd381aca8d39caa250e02d190b23be40f555d3e97fb70086
data/.rdoc_options ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ main_page: README.md
3
+ page_dir: docs
data/BSDL ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
+ SUCH DAMAGE.
data/COPYING ADDED
@@ -0,0 +1,56 @@
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a. place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b. use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c. give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d. make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a. distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b. accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c. give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d. make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
data/Rakefile CHANGED
@@ -7,11 +7,4 @@ Rake::TestTask.new(:test) do |t|
7
7
  t.test_files = FileList["test/**/test_*.rb"]
8
8
  end
9
9
 
10
- task :sync_tool do
11
- require 'fileutils'
12
- FileUtils.cp "../ruby/tool/lib/core_assertions.rb", "./test/lib"
13
- FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
14
- FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
15
- end
16
-
17
10
  task :default => :test
data/docs/dir.rb ADDED
@@ -0,0 +1,6 @@
1
+ # This file is to show this class in the generated pages and to make
2
+ # RDoc coverage 100%.
3
+
4
+ # Built-in class represents a directory in the underlying file system.
5
+ class Dir
6
+ end
data/lib/tmpdir.rb CHANGED
@@ -13,22 +13,32 @@ end
13
13
 
14
14
  class Dir
15
15
 
16
- @@systmpdir ||= defined?(Etc.systmpdir) ? Etc.systmpdir : '/tmp'
16
+ # Class variables are inaccessible from non-main Ractor.
17
+ # And instance variables too, in Ruby 3.0.
18
+
19
+ # System-wide temporary directory path
20
+ SYSTMPDIR = (defined?(Etc.systmpdir) ? Etc.systmpdir.freeze : '/tmp')
21
+ private_constant :SYSTMPDIR
17
22
 
18
23
  ##
19
24
  # Returns the operating system's temporary file path.
25
+ #
26
+ # require 'tmpdir'
27
+ # Dir.tmpdir # => "/tmp"
20
28
 
21
29
  def self.tmpdir
22
- ['TMPDIR', 'TMP', 'TEMP', ['system temporary path', @@systmpdir], ['/tmp']*2, ['.']*2].find do |name, dir|
30
+ ['TMPDIR', 'TMP', 'TEMP', ['system temporary path', SYSTMPDIR], ['/tmp']*2, ['.']*2].find do |name, dir|
23
31
  unless dir
24
- next if !(dir = ENV[name]) or dir.empty?
32
+ next if !(dir = ENV[name] rescue next) or dir.empty?
25
33
  end
26
34
  dir = File.expand_path(dir)
27
35
  stat = File.stat(dir) rescue next
28
36
  case
29
37
  when !stat.directory?
30
38
  warn "#{name} is not a directory: #{dir}"
31
- when !stat.writable?
39
+ when !File.writable?(dir)
40
+ # We call File.writable?, not stat.writable?, because you can't tell if a dir is actually
41
+ # writable just from stat; OS mechanisms other than user/group/world bits can affect this.
32
42
  warn "#{name} is not writable: #{dir}"
33
43
  when stat.world_writable? && !stat.sticky?
34
44
  warn "#{name} is world-writable: #{dir}"
@@ -40,6 +50,11 @@ class Dir
40
50
 
41
51
  # Dir.mktmpdir creates a temporary directory.
42
52
  #
53
+ # require 'tmpdir'
54
+ # Dir.mktmpdir {|dir|
55
+ # # use the directory
56
+ # }
57
+ #
43
58
  # The directory is created with 0700 permission.
44
59
  # Application should not change the permission to make the temporary directory accessible from other users.
45
60
  #
@@ -94,9 +109,10 @@ class Dir
94
109
  yield path.dup
95
110
  ensure
96
111
  unless base
97
- stat = File.stat(File.dirname(path))
112
+ base = File.dirname(path)
113
+ stat = File.stat(base)
98
114
  if stat.world_writable? and !stat.sticky?
99
- raise ArgumentError, "parent directory is world writable but not sticky"
115
+ raise ArgumentError, "parent directory is world writable but not sticky: #{base}"
100
116
  end
101
117
  end
102
118
  FileUtils.remove_entry path
@@ -118,22 +134,27 @@ class Dir
118
134
  UNUSABLE_CHARS = "^,-.0-9A-Z_a-z~"
119
135
 
120
136
  # Dedicated random number generator
121
- RANDOM = Random.new
137
+ RANDOM = Object.new
122
138
  class << RANDOM # :nodoc:
123
139
  # Maximum random number
124
140
  MAX = 36**6 # < 0x100000000
125
141
 
126
142
  # Returns new random string upto 6 bytes
127
143
  def next
128
- rand(MAX).to_s(36)
144
+ (::Random.urandom(4).unpack1("L")%MAX).to_s(36)
129
145
  end
130
146
  end
147
+ RANDOM.freeze
131
148
  private_constant :RANDOM
132
149
 
133
150
  # Generates and yields random names to create a temporary name
134
151
  def create(basename, tmpdir=nil, max_try: nil, **opts)
135
152
  origdir = tmpdir
136
- tmpdir ||= tmpdir()
153
+ if tmpdir
154
+ raise ArgumentError, "empty parent path" if tmpdir.empty?
155
+ else
156
+ tmpdir = tmpdir()
157
+ end
137
158
  n = nil
138
159
  prefix, suffix = basename
139
160
  prefix = (String.try_convert(prefix) or
@@ -152,7 +173,7 @@ class Dir
152
173
  n ||= 0
153
174
  n += 1
154
175
  retry if !max_try or n < max_try
155
- raise "cannot generate temporary name using `#{basename}' under `#{tmpdir}'"
176
+ raise "cannot generate temporary name using '#{basename}' under '#{tmpdir}'"
156
177
  end
157
178
  path
158
179
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tmpdir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukihiro Matsumoto
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-05 00:00:00.000000000 Z
11
+ date: 2024-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fileutils
@@ -32,17 +32,13 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - ".document"
35
- - ".github/dependabot.yml"
36
- - ".github/workflows/test.yml"
37
- - ".gitignore"
38
- - Gemfile
39
- - Gemfile.lock
35
+ - ".rdoc_options"
36
+ - BSDL
37
+ - COPYING
40
38
  - README.md
41
39
  - Rakefile
42
- - bin/console
43
- - bin/setup
40
+ - docs/dir.rb
44
41
  - lib/tmpdir.rb
45
- - tmpdir.gemspec
46
42
  homepage: https://github.com/ruby/tmpdir
47
43
  licenses:
48
44
  - Ruby
@@ -50,7 +46,7 @@ licenses:
50
46
  metadata:
51
47
  homepage_uri: https://github.com/ruby/tmpdir
52
48
  source_code_uri: https://github.com/ruby/tmpdir
53
- post_install_message:
49
+ post_install_message:
54
50
  rdoc_options: []
55
51
  require_paths:
56
52
  - lib
@@ -65,8 +61,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
61
  - !ruby/object:Gem::Version
66
62
  version: '0'
67
63
  requirements: []
68
- rubygems_version: 3.4.0.dev
69
- signing_key:
64
+ rubygems_version: 3.5.11
65
+ signing_key:
70
66
  specification_version: 4
71
67
  summary: Extends the Dir class to manage the OS temporary file path.
72
68
  test_files: []
@@ -1,6 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: 'github-actions'
4
- directory: '/'
5
- schedule:
6
- interval: 'weekly'
@@ -1,27 +0,0 @@
1
- name: test
2
-
3
- on: [push, pull_request]
4
-
5
- jobs:
6
- build:
7
- name: build (${{ matrix.ruby }} / ${{ matrix.os }})
8
- strategy:
9
- matrix:
10
- ruby: [ '3.1', '3.0', '2.7', head ]
11
- os: [ ubuntu-latest, macos-latest, windows-latest ]
12
- exclude:
13
- - { os: windows-latest, ruby: head }
14
- include:
15
- - { os: windows-latest, ruby: mingw }
16
- - { os: windows-latest, ruby: mswin }
17
- runs-on: ${{ matrix.os }}
18
- steps:
19
- - uses: actions/checkout@v3
20
- - name: Set up Ruby
21
- uses: ruby/setup-ruby@v1
22
- with:
23
- ruby-version: ${{ matrix.ruby }}
24
- - name: Install dependencies
25
- run: bundle install
26
- - name: Run test
27
- run: rake test
data/.gitignore DELETED
@@ -1,8 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- gem "rake"
6
- gem "test-unit"
data/Gemfile.lock DELETED
@@ -1,23 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- tmpdir (0.1.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- power_assert (1.1.5)
10
- rake (12.3.3)
11
- test-unit (3.3.5)
12
- power_assert
13
-
14
- PLATFORMS
15
- ruby
16
-
17
- DEPENDENCIES
18
- rake
19
- test-unit
20
- tmpdir!
21
-
22
- BUNDLED WITH
23
- 2.1.4
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "tmpdir"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/tmpdir.gemspec DELETED
@@ -1,26 +0,0 @@
1
- Gem::Specification.new do |spec|
2
- spec.name = "tmpdir"
3
- spec.version = "0.1.3"
4
- spec.authors = ["Yukihiro Matsumoto"]
5
- spec.email = ["matz@ruby-lang.org"]
6
-
7
- spec.summary = %q{Extends the Dir class to manage the OS temporary file path.}
8
- spec.description = %q{Extends the Dir class to manage the OS temporary file path.}
9
- spec.homepage = "https://github.com/ruby/tmpdir"
10
- spec.licenses = ["Ruby", "BSD-2-Clause"]
11
- spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
12
-
13
- spec.metadata["homepage_uri"] = spec.homepage
14
- spec.metadata["source_code_uri"] = spec.homepage
15
-
16
- # Specify which files should be added to the gem when it is released.
17
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
- `git ls-files -z 2>/dev/null`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
- end
21
- spec.bindir = "exe"
22
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
- spec.require_paths = ["lib"]
24
-
25
- spec.add_dependency "fileutils"
26
- end