ruby-changes:39761
From: shugo <ko1@a...>
Date: Sat, 12 Sep 2015 21:30:01 +0900 (JST)
Subject: [ruby-changes:39761] shugo:r51842 (trunk): * lib/net/ftp.rb (FACT_PARSERS): support system dependent facts
shugo 2015-09-12 21:29:32 +0900 (Sat, 12 Sep 2015) New Revision: 51842 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51842 Log: * lib/net/ftp.rb (FACT_PARSERS): support system dependent facts UNIX.mode, UNIX.owner, UNIX.group, UNIX.ctime, and UNIX.atime. Modified files: trunk/ChangeLog trunk/lib/net/ftp.rb trunk/test/net/ftp/test_ftp.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 51841) +++ ChangeLog (revision 51842) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Sep 12 21:27:22 2015 Shugo Maeda <shugo@r...> + + * lib/net/ftp.rb (FACT_PARSERS): support system dependent facts + UNIX.mode, UNIX.owner, UNIX.group, UNIX.ctime, and UNIX.atime. + Sat Sep 12 19:08:58 2015 Nobuyoshi Nakada <nobu@r...> * win32/win32.c (rb_w32_dup2): should return the new fd on Index: lib/net/ftp.rb =================================================================== --- lib/net/ftp.rb (revision 51841) +++ lib/net/ftp.rb (revision 51842) @@ -772,7 +772,8 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L772 CASE_DEPENDENT_PARSER = ->(value) { value } CASE_INDEPENDENT_PARSER = ->(value) { value.downcase } - INTEGER_PARSER = ->(value) { value.to_i } + 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) @@ -783,7 +784,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L784 end } FACT_PARSERS = Hash.new(CASE_DEPENDENT_PARSER) - FACT_PARSERS["size"] = INTEGER_PARSER + FACT_PARSERS["size"] = DECIMAL_PARSER FACT_PARSERS["modify"] = TIME_PARSER FACT_PARSERS["create"] = TIME_PARSER FACT_PARSERS["type"] = CASE_INDEPENDENT_PARSER @@ -792,6 +793,11 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L793 FACT_PARSERS["lang"] = CASE_INDEPENDENT_PARSER FACT_PARSERS["media-type"] = CASE_INDEPENDENT_PARSER FACT_PARSERS["charset"] = CASE_INDEPENDENT_PARSER + FACT_PARSERS["unix.mode"] = OCTAL_PARSER + FACT_PARSERS["unix.owner"] = DECIMAL_PARSER + FACT_PARSERS["unix.group"] = DECIMAL_PARSER + FACT_PARSERS["unix.ctime"] = TIME_PARSER + FACT_PARSERS["unix.atime"] = TIME_PARSER def parse_mlsx_entry(entry) facts, pathname = entry.split(" ") Index: test/net/ftp/test_ftp.rb =================================================================== --- test/net/ftp/test_ftp.rb (revision 51841) +++ test/net/ftp/test_ftp.rb (revision 51842) @@ -1125,7 +1125,7 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1125 sock.print("220 (test_ftp).\r\n") commands.push(sock.gets) sock.print("250- Listing foo\r\n") - sock.print(" Type=file;Unique=FC00U1E554A;Size=1234567;Modify=20131220035929;Perm=r; /foo\r\n") + sock.print(" Type=file;Unique=FC00U1E554A;Size=1234567;Modify=20131220035929;Perm=r;Unix.mode=0644;Unix.owner=122;Unix.group=0;Unix.ctime=20131220120140;Unix.atime=20131220131139; /foo\r\n") sock.print("250 End\r\n") commands.push(sock.gets) sock.print("250 Malformed response\r\n") @@ -1148,6 +1148,9 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1148 assert_equal("FC00U1E554A", entry.facts["unique"]) assert_equal(1234567, entry.facts["size"]) assert_equal("r", entry.facts["perm"]) + assert_equal(0644, entry.facts["unix.mode"]) + assert_equal(122, entry.facts["unix.owner"]) + assert_equal(0, entry.facts["unix.group"]) modify = entry.facts["modify"] assert_equal(2013, modify.year) assert_equal(12, modify.month) @@ -1156,6 +1159,14 @@ EOF https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L1159 assert_equal(59, modify.min) assert_equal(29, modify.sec) assert_equal(true, modify.utc?) + ctime = entry.facts["unix.ctime"] + assert_equal(12, ctime.hour) + assert_equal(1, ctime.min) + assert_equal(40, ctime.sec) + atime = entry.facts["unix.atime"] + assert_equal(13, atime.hour) + assert_equal(11, atime.min) + assert_equal(39, atime.sec) assert_match("MLST foo\r\n", commands.shift) assert_raise(Net::FTPProtoError) do ftp.mlst("foo") -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/