[前][次][番号順一覧][スレッド一覧]

ruby-changes:37471

From: shugo <ko1@a...>
Date: Tue, 10 Feb 2015 11:26:23 +0900 (JST)
Subject: [ruby-changes:37471] shugo:r49552 (trunk): * lib/net/ftp.rb (chdir, delete, gettextfile, mdtm, mkdir, nlst,

shugo	2015-02-10 11:26:06 +0900 (Tue, 10 Feb 2015)

  New Revision: 49552

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49552

  Log:
    * lib/net/ftp.rb (chdir, delete, gettextfile, mdtm, mkdir, nlst,
      putbinaryfile, puttextfile, rename, rmdir, size): support
      Pathname. Patch by Joe Rafaniello. [fix GH-828]

  Modified files:
    trunk/ChangeLog
    trunk/lib/net/ftp.rb
    trunk/test/net/ftp/test_ftp.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49551)
+++ ChangeLog	(revision 49552)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Feb 10 11:19:11 2015  Shugo Maeda  <shugo@r...>
+
+	* lib/net/ftp.rb (chdir, delete, gettextfile, mdtm, mkdir, nlst,
+	  putbinaryfile, puttextfile, rename, rmdir, size): support
+	  Pathname. Patch by Joe Rafaniello. [fix GH-828]
+
 Mon Feb  9 16:36:12 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* tool/make-snapshot (package): get rid of loading unbundled and
Index: lib/net/ftp.rb
===================================================================
--- lib/net/ftp.rb	(revision 49551)
+++ lib/net/ftp.rb	(revision 49552)
@@ -618,7 +618,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L618
       end
       begin
         f.binmode if localfile
-        retrbinary("RETR " + remotefile.to_s, blocksize, rest_offset) do |data|
+        retrbinary("RETR #{remotefile}", blocksize, rest_offset) do |data|
           f.write(data) if localfile
           yield(data) if block_given?
           result.concat(data) if result
@@ -644,7 +644,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L644
         result = ""
       end
       begin
-        retrlines("RETR " + remotefile) do |line, newline|
+        retrlines("RETR #{remotefile}") do |line, newline|
           l = newline ? line + "\n" : line
           f.print(l) if localfile
           yield(line, newline) if block_given?
@@ -689,9 +689,9 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L689
       begin
         f.binmode
         if rest_offset
-          storbinary("APPE " + remotefile, f, blocksize, rest_offset, &block)
+          storbinary("APPE #{remotefile}", f, blocksize, rest_offset, &block)
         else
-          storbinary("STOR " + remotefile, f, blocksize, rest_offset, &block)
+          storbinary("STOR #{remotefile}", f, blocksize, rest_offset, &block)
         end
       ensure
         f.close
@@ -706,7 +706,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L706
     def puttextfile(localfile, remotefile = File.basename(localfile), &block) # :yield: line
       f = open(localfile)
       begin
-        storlines("STOR " + remotefile, f, &block)
+        storlines("STOR #{remotefile}", f, &block)
       ensure
         f.close
       end
@@ -742,7 +742,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L742
     def nlst(dir = nil)
       cmd = "NLST"
       if dir
-        cmd = cmd + " " + dir
+        cmd = "#{cmd} #{dir}"
       end
       files = []
       retrlines(cmd) do |line|
@@ -758,7 +758,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L758
     def list(*args, &block) # :yield: line
       cmd = "LIST"
       args.each do |arg|
-        cmd = cmd + " " + arg.to_s
+        cmd = "#{cmd} #{arg}"
       end
       if block
         retrlines(cmd, &block)
@@ -777,18 +777,18 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L777
     # Renames a file on the server.
     #
     def rename(fromname, toname)
-      resp = sendcmd("RNFR " + fromname)
+      resp = sendcmd("RNFR #{fromname}")
       if resp[0] != ?3
         raise FTPReplyError, resp
       end
-      voidcmd("RNTO " + toname)
+      voidcmd("RNTO #{toname}")
     end
 
     #
     # Deletes a file on the server.
     #
     def delete(filename)
-      resp = sendcmd("DELE " + filename)
+      resp = sendcmd("DELE #{filename}")
       if resp[0, 3] == "250"
         return
       elsif resp[0] == ?5
@@ -812,7 +812,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L812
           end
         end
       end
-      cmd = "CWD " + dirname
+      cmd = "CWD #{dirname}"
       voidcmd(cmd)
     end
 
@@ -821,7 +821,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L821
     #
     def size(filename)
       with_binary(true) do
-        resp = sendcmd("SIZE " + filename)
+        resp = sendcmd("SIZE #{filename}")
         if resp[0, 3] != "213"
           raise FTPReplyError, resp
         end
@@ -845,7 +845,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L845
     # Creates a remote directory.
     #
     def mkdir(dirname)
-      resp = sendcmd("MKD " + dirname)
+      resp = sendcmd("MKD #{dirname}")
       return parse257(resp)
     end
 
@@ -853,7 +853,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L853
     # Removes a remote directory.
     #
     def rmdir(dirname)
-      voidcmd("RMD " + dirname)
+      voidcmd("RMD #{dirname}")
     end
 
     #
@@ -907,7 +907,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L907
     # Use +mtime+ if you want a parsed Time instance.
     #
     def mdtm(filename)
-      resp = sendcmd("MDTM " + filename)
+      resp = sendcmd("MDTM #{filename}")
       if resp[0, 3] == "213"
         return resp[3 .. -1].strip
       end
Index: test/net/ftp/test_ftp.rb
===================================================================
--- test/net/ftp/test_ftp.rb	(revision 49551)
+++ test/net/ftp/test_ftp.rb	(revision 49552)
@@ -767,6 +767,84 @@ class FTPTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/ftp/test_ftp.rb#L767
     end
   end
 
+  def test_pathnames
+    require 'pathname'
+
+    commands = []
+    server = create_ftp_server(0.2) { |sock|
+      sock.print("220 (test_ftp).\r\n")
+      commands.push(sock.gets)
+      sock.print("331 Please specify the password.\r\n")
+      commands.push(sock.gets)
+      sock.print("230 Login successful.\r\n")
+      commands.push(sock.gets)
+      sock.print("200 Switching to Binary mode.\r\n")
+      commands.push(sock.gets)
+      sock.print("257 'foo' directory created.\r\n")
+      commands.push(sock.gets)
+      sock.print("250 CWD command successful.\r\n")
+      commands.push(sock.gets)
+      sock.print("250 CWD command successful.\r\n")
+      commands.push(sock.gets)
+      sock.print("250 RMD command successful.\r\n")
+      commands.push(sock.gets)
+      sock.print("213 test.txt  Fri, 11 Jan 2013 11:20:41 -0500.\r\n")
+      commands.push(sock.gets)
+      sock.print("213 test.txt  16.\r\n")
+      commands.push(sock.gets)
+      sock.print("350 File exists, ready for destination name\r\n")
+      commands.push(sock.gets)
+      sock.print("250 RNTO command successful.\r\n")
+      commands.push(sock.gets)
+      sock.print("250 DELE command successful.\r\n")
+    }
+
+    begin
+      begin
+        dir   = Pathname.new("foo")
+        file  = Pathname.new("test.txt")
+        file2 = Pathname.new("test2.txt")
+        ftp   = Net::FTP.new
+        ftp.connect(SERVER_ADDR, server.port)
+        ftp.login
+        ftp.mkdir(dir)
+        ftp.chdir(dir)
+        ftp.chdir("..")
+        ftp.rmdir(dir)
+        ftp.mdtm(file)
+        ftp.size(file)
+        ftp.rename(file, file2)
+        ftp.delete(file)
+
+        # TODO: These commented tests below expose the error but don't test anything:
+        #   TypeError: no implicit conversion of Pathname into String
+        # ftp.nlst(dir)
+        # ftp.putbinaryfile(Pathname.new("/etc/hosts"), file2)
+        # ftp.puttextfile(Pathname.new("/etc/hosts"), file2)
+        # ftp.gettextfile(Pathname.new("/etc/hosts"), file2)
+        # ftp.getbinaryfile(Pathname.new("/etc/hosts"), file2)
+        # ftp.list(dir, dir, dir)
+
+        assert_match(/\AUSER /, commands.shift)
+        assert_match(/\APASS /, commands.shift)
+        assert_match(/\ATYPE /, commands.shift)
+        assert_match(/\AMKD /, commands.shift)
+        assert_match(/\ACWD /, commands.shift)
+        assert_match(/\ACDUP/, commands.shift)
+        assert_match(/\ARMD /, commands.shift)
+        assert_match(/\AMDTM /, commands.shift)
+        assert_match(/\ASIZE /, commands.shift)
+        assert_match(/\ARNFR /, commands.shift)
+        assert_match(/\ARNTO /, commands.shift)
+        assert_match(/\ADELE /, commands.shift)
+      ensure
+        ftp.close if ftp
+      end
+    ensure
+      server.close
+    end
+  end
+
   private
 
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]