aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--lib/net/ftp.rb10
-rw-r--r--test/net/ftp/test_ftp.rb13
3 files changed, 25 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 2516b5e939..bb9401f7a0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/lib/net/ftp.rb b/lib/net/ftp.rb
index f4f7494a04..d3bb450a93 100644
--- a/lib/net/ftp.rb
+++ b/lib/net/ftp.rb
@@ -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(" ")
diff --git a/test/net/ftp/test_ftp.rb b/test/net/ftp/test_ftp.rb
index d347a30a1e..711bbab6f7 100644
--- a/test/net/ftp/test_ftp.rb
+++ b/test/net/ftp/test_ftp.rb
@@ -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")