Shorten tmpdir path
This commit is contained in:
parent
e61f76ce9e
commit
777daae049
@ -1,14 +1,23 @@
|
|||||||
require "tmpdir"
|
|
||||||
require "fileutils"
|
|
||||||
|
|
||||||
template = "rubytest."
|
template = "rubytest."
|
||||||
if (tmpdir = Dir.mktmpdir(template)).size > 50 and File.directory?("/tmp")
|
|
||||||
|
# This path is only for tests.
|
||||||
|
# Assume the directory by these environment variables are safe.
|
||||||
|
base = [ENV["TMPDIR"], ENV["TMP"], "/tmp"].find do |tmp|
|
||||||
|
next unless tmp and tmp.size <= 50 and File.directory?(tmp)
|
||||||
# On macOS, the default TMPDIR is very long, inspite of UNIX socket
|
# On macOS, the default TMPDIR is very long, inspite of UNIX socket
|
||||||
# path length is limited.
|
# path length is limited.
|
||||||
# Assume "/tmp" always exists on UNIX-like systems where UNIX socket
|
#
|
||||||
# is available, otherwise no need to shorten TMPDIR.
|
# Also Rubygems creates its own temporary directory per tests, and
|
||||||
Dir.rmdir(tmpdir)
|
# some tests copy the full path of gemhome there. In that caes, the
|
||||||
tmpdir = Dir.mktmpdir(template, "/tmp")
|
# path contains both temporary names twice, and can exceed path name
|
||||||
|
# limit very easily.
|
||||||
|
tmp
|
||||||
|
end
|
||||||
|
begin
|
||||||
|
tmpdir = File.join(base, template + Random.new_seed.to_s(36)[-6..-1])
|
||||||
|
Dir.mkdir(tmpdir, 0o700)
|
||||||
|
rescue Errno::EEXIST
|
||||||
|
retry
|
||||||
end
|
end
|
||||||
# warn "tmpdir(#{tmpdir.size}) = #{tmpdir}"
|
# warn "tmpdir(#{tmpdir.size}) = #{tmpdir}"
|
||||||
|
|
||||||
@ -80,6 +89,7 @@ END {
|
|||||||
File.unlink(path)
|
File.unlink(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
require "fileutils"
|
||||||
FileUtils.rm_rf(tmpdir)
|
FileUtils.rm_rf(tmpdir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user