diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-09-28 07:10:25 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-09-28 07:10:25 +0000 |
commit | 040ae9104055d7a4789b46ead215287d5d6ff305 (patch) | |
tree | 2acb3ab276b28320e9a84f8f23988d96e13ded76 /lib | |
parent | 4191a6b90d3eeb63a31609dba29a1904efee3738 (diff) | |
download | ruby-040ae9104055d7a4789b46ead215287d5d6ff305.tar.gz |
* lib/net/ftp.rb (mtime): parse decimal fractions of a second as
specified in RFC 3659.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51963 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/net/ftp.rb | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb index fd11acb8b5..795e1cbdc3 100644 --- a/lib/net/ftp.rb +++ b/lib/net/ftp.rb @@ -888,14 +888,15 @@ module Net CASE_INDEPENDENT_PARSER = ->(value) { value.downcase } DECIMAL_PARSER = ->(value) { value.to_i } OCTAL_PARSER = ->(value) { value.to_i(8) } - TIME_PARSER = ->(value) { - t = Time.strptime(value.sub(/\.\d+\z/, "") + "Z", "%Y%m%d%H%M%S%z") - fractions = value.slice(/\.(\d+)\z/, 1) - if fractions - t + fractions.to_i.quo(10 ** fractions.size) - else - t - end + TIME_PARSER = ->(value, local = false) { + unless /\A(?<year>\d{4})(?<month>\d{2})(?<day>\d{2}) + (?<hour>\d{2})(?<min>\d{2})(?<sec>\d{2}) + (\.(?<fractions>\d+))?/x =~ value + raise FTPProtoError, "invalid time-val: #{value}" + end + usec = fractions.to_i * 10 ** (6 - fractions.to_s.size) + Time.send(local ? :local : :utc, + year, month, day, hour, min, sec, fractions) } FACT_PARSERS = Hash.new(CASE_DEPENDENT_PARSER) FACT_PARSERS["size"] = DECIMAL_PARSER @@ -1028,16 +1029,12 @@ module Net end end - MDTM_REGEXP = /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/ # :nodoc: - # # Returns the last modification time of the (remote) file. If +local+ is # +true+, it is returned as a local time, otherwise it's a UTC time. # def mtime(filename, local = false) - str = mdtm(filename) - ary = str.scan(MDTM_REGEXP)[0].collect {|i| i.to_i} - return local ? Time.local(*ary) : Time.gm(*ary) + return TIME_PARSER.(mdtm(filename), local) end # |