1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/net/ftp.rb (FACT_PARSERS): support system dependent facts

UNIX.mode, UNIX.owner, UNIX.group, UNIX.ctime, and UNIX.atime.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51842 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shugo 2015-09-12 12:29:32 +00:00
parent f6d77bf560
commit 2ec793ab27
3 changed files with 25 additions and 3 deletions

View file

@ -1,3 +1,8 @@
Sat Sep 12 21:27:22 2015 Shugo Maeda <shugo@ruby-lang.org>
* 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@ruby-lang.org>
* win32/win32.c (rb_w32_dup2): should return the new fd on

View file

@ -772,7 +772,8 @@ module Net
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
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
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(" ")

View file

@ -1125,7 +1125,7 @@ EOF
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
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
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")