Skip to content

Commit

Permalink
Ignore the timeconfig symlink included on Slackware.
Browse files Browse the repository at this point in the history
Resolves #64.

(cherry picked from commit de9f4bc)
  • Loading branch information
philr committed Mar 19, 2017
1 parent 5dedceb commit 400aa76
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/tzinfo/zoneinfo_data_source.rb
Expand Up @@ -349,8 +349,9 @@ def load_timezone_index
# localtime current local timezone (may be a link).
# posix, posixrules and right are directories containing other versions of the zoneinfo files.
# src is a directory containing the tzdata source included on Solaris.
# timeconfig is a symlink included on Slackware.

enum_timezones(nil, ['+VERSION', 'localtime', 'posix', 'posixrules', 'right', 'src']) do |identifier|
enum_timezones(nil, ['+VERSION', 'localtime', 'posix', 'posixrules', 'right', 'src', 'timeconfig']) do |identifier|
index << identifier
end

Expand Down
63 changes: 63 additions & 0 deletions test/tc_zoneinfo_data_source.rb
Expand Up @@ -395,6 +395,39 @@ def test_load_timezone_info_ignored_plus_version_file
end
end

def test_load_timezone_info_ignored_timeconfig_symlink
# Slackware includes a symlink named timeconfig that points at /usr/sbin/timeconfig.

Dir.mktmpdir('tzinfo_test_target') do |target_dir|
target_path = File.join(target_dir, 'timeconfig')

File.open(target_path, 'w') do |f|
f.write("#!/bin/sh\n")
f.write("#\n")
f.write('# timeconfig Slackware Linux timezone configuration utility.\n')
end

Dir.mktmpdir('tzinfo_test') do |dir|
FileUtils.touch(File.join(dir, 'zone.tab'))
FileUtils.touch(File.join(dir, 'iso3166.tab'))
FileUtils.cp(File.join(@data_source.zoneinfo_dir, 'EST'), File.join(dir, 'EST'))

symlink_path = File.join(dir, 'timeconfig')
begin
FileUtils.ln_s(target_path, symlink_path)
rescue NotImplementedError
FileUtils.cp(target_path, symlink_path)
end

data_source = ZoneinfoDataSource.new(dir)

assert_raises(InvalidTimezoneIdentifier) do
data_source.load_timezone_info('timeconfig')
end
end
end
end

def test_load_timezone_info_nil
assert_raises(InvalidTimezoneIdentifier) do
@data_source.load_timezone_info(nil)
Expand Down Expand Up @@ -714,6 +747,36 @@ def test_timezone_identifiers_ignored_plus_version_file
end
end

def test_timezone_identifiers_ignored_timeconfig_symlink
# Slackware includes a symlink named timeconfig that points at /usr/sbin/timeconfig.

Dir.mktmpdir('tzinfo_test_target') do |target_dir|
target_path = File.join(target_dir, 'timeconfig')

File.open(target_path, 'w') do |f|
f.write("#!/bin/sh\n")
f.write("#\n")
f.write('# timeconfig Slackware Linux timezone configuration utility.\n')
end

Dir.mktmpdir('tzinfo_test') do |dir|
FileUtils.touch(File.join(dir, 'zone.tab'))
FileUtils.touch(File.join(dir, 'iso3166.tab'))
FileUtils.cp(File.join(@data_source.zoneinfo_dir, 'EST'), File.join(dir, 'EST'))

symlink_path = File.join(dir, 'timeconfig')
begin
FileUtils.ln_s(target_path, symlink_path)
rescue NotImplementedError
FileUtils.cp(target_path, symlink_path)
end

data_source = ZoneinfoDataSource.new(dir)
assert_array_same_items(['EST'], data_source.timezone_identifiers)
end
end
end

def test_timezone_identifiers_ignored_src_directory
# Solaris includes a src directory containing the source timezone data files
# from the tzdata distribution. These should be ignored.
Expand Down

0 comments on commit 400aa76

Please sign in to comment.