Skip to content

Commit ab58703

Browse files
committed
Merge release/0.5.13
2 parents 316c0db + 125ea62 commit ab58703

File tree

5 files changed

+51
-33
lines changed

5 files changed

+51
-33
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ The `clj-ssh.ssh` namespace should be used for SSH from functional code.
5858
(with-connection session
5959
(let [result (ssh session {:in "echo hello"})]
6060
(println (result :out)))
61-
(let [result (ssh session {:cmd "ls"}]
61+
(let [result (ssh session {:cmd "ls"})]
6262
(println (second result)))))))
6363
```
6464

@@ -163,7 +163,7 @@ Thanks to [Ryan Stradling](http://github.com/rstradling) for these.
163163
Via [clojars](http://clojars.org) and
164164
[Leiningen](http://github.com/technomancy/leiningen).
165165

166-
:dependencies [clj-ssh "0.5.12"]
166+
:dependencies [clj-ssh "0.5.13"]
167167

168168
or your favourite maven repository aware tool.
169169

ReleaseNotes.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
## 0.5.13
2+
3+
- Make clojure dependency have provided scope
4+
Closes #25
5+
6+
- Fix race condition in ssh-exec function when command finishes before we
7+
enter with-channel-connection
8+
9+
- ssh/download: fix :recursive and :preserve flags arity errors.
10+
Recursive still doesn't work correctly: clj-ssh writes every file into the
11+
same output.
12+
13+
- Fixed recursive scp invocation.
14+
15+
- fix trace/tracef mixup.
16+
17+
- Fix missing parens
18+
119
## 0.5.12
220

321
- Update jsch and jsch agentproxy

project.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
(def agentproxy-version "0.0.9")
22

3-
(defproject clj-ssh "0.5.12"
3+
(defproject clj-ssh "0.5.13"
44
:description "Library for using SSH from clojure."
55
:url "https://github.com/hugoduncan/clj-ssh"
66
:license {:name "Eclipse Public License"
77
:url "http://www.eclipse.org/legal/epl-v10.html"}
8-
:dependencies [[org.clojure/clojure "1.4.0"]
9-
[org.clojure/tools.logging "0.2.6"
8+
:dependencies [[org.clojure/tools.logging "0.2.6"
109
:exclusions [org.clojure/clojure]]
1110
[com.jcraft/jsch.agentproxy.usocket-jna ~agentproxy-version]
1211
[com.jcraft/jsch.agentproxy.usocket-nc ~agentproxy-version]
@@ -15,4 +14,5 @@
1514
[com.jcraft/jsch.agentproxy.core ~agentproxy-version]
1615
[com.jcraft/jsch.agentproxy.jsch ~agentproxy-version]
1716
[com.jcraft/jsch "0.1.53"]]
18-
:jvm-opts ["-Djava.awt.headless=true"])
17+
:jvm-opts ["-Djava.awt.headless=true"]
18+
:profiles {:provided {:dependencies [[org.clojure/clojure "1.4.0"]]}})

src/clj_ssh/ssh.clj

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -686,16 +686,15 @@ config options."
686686
{:channel exec
687687
:out-stream out-inputstream
688688
:err-stream err-inputstream}
689-
(with-channel-connection exec
690-
(while (connected-channel? exec)
691-
(Thread/sleep 100))
692-
{:exit (.getExitStatus exec)
693-
:out (if (= :bytes out)
694-
(.toByteArray ^ByteArrayOutputStream out-stream)
695-
(.toString out-stream))
696-
:err (if (= :bytes out)
697-
(.toByteArray ^ByteArrayOutputStream err-stream)
698-
(.toString err-stream))}))))
689+
(do (while (connected-channel? exec)
690+
(Thread/sleep 100))
691+
{:exit (.getExitStatus exec)
692+
:out (if (= :bytes out)
693+
(.toByteArray ^ByteArrayOutputStream out-stream)
694+
(.toString out-stream))
695+
:err (if (= :bytes out)
696+
(.toByteArray ^ByteArrayOutputStream err-stream)
697+
(.toString err-stream))}))))
699698

700699
(defn ssh
701700
"Execute commands over ssh.
@@ -856,7 +855,7 @@ cmd specifies a command to exec. Valid commands are:
856855
(defn- scp-send-command
857856
"Send command to the specified output stream"
858857
[^OutputStream out ^InputStream in ^String cmd-string]
859-
(.write out (.getBytes cmd-string))
858+
(.write out (.getBytes (str cmd-string "\n")))
860859
(.flush out)
861860
(logging/tracef "Sent command %s" cmd-string)
862861
(scp-receive-ack in)
@@ -882,38 +881,34 @@ cmd specifies a command to exec. Valid commands are:
882881

883882
(defn- scp-copy-file
884883
"Send acknowledgement to the specified output stream"
885-
[send recv ^File file {:keys [mode buffer-size preserve]
884+
[^OutputStream send ^InputStream recv ^File file {:keys [mode buffer-size preserve]
886885
:or {mode 0644 buffer-size 1492 preserve false}}]
887-
(logging/tracef "Sending %s" (.getAbsolutePath file))
886+
888887
(when preserve
889888
(scp-send-command
890889
send recv
891-
(format "P %d 0 %d 0\n" (.lastModified file) (.lastModified file))))
890+
(format "P%d 0 %d 0" (.lastModified file) (.lastModified file))))
892891
(scp-send-command
893892
send recv
894-
(format "C%04o %d %s\n" mode (.length file) (.getName file)))
895-
(with-open [fs (FileInputStream. file)]
896-
(io/copy fs send :buffer-size buffer-size))
893+
(format "C%04o %d %s" mode (.length file) (.getName file)))
894+
(logging/tracef "Sending %s" (.getAbsolutePath file))
895+
(io/copy file send :buffer-size buffer-size)
897896
(scp-send-ack send)
898-
(logging/trace "Sent ACK after send")
899-
(scp-receive-ack recv)
900-
(logging/trace "Received ACK after send"))
897+
(logging/trace "Receiving ACK after send")
898+
(scp-receive-ack recv))
901899

902900
(defn- scp-copy-dir
903901
"Send acknowledgement to the specified output stream"
904902
[send recv ^File dir {:keys [dir-mode] :or {dir-mode 0755} :as options}]
905-
(logging/trace "Sending directory %s" (.getAbsolutePath dir))
903+
(logging/tracef "Sending directory %s" (.getAbsolutePath dir))
906904
(scp-send-command
907905
send recv
908906
(format "D%04o 0 %s" dir-mode (.getName dir)))
909907
(doseq [^File file (.listFiles dir)]
910908
(cond
911909
(.isFile file) (scp-copy-file send recv file options)
912910
(.isDirectory file) (scp-copy-dir send recv file options)))
913-
(scp-send-ack send)
914-
(logging/trace "Sent ACK after send")
915-
(scp-receive-ack recv)
916-
(logging/trace "Received ACK after send"))
911+
(scp-send-command send recv "E"))
917912

918913
(defn- scp-files
919914
[paths recursive]
@@ -1025,7 +1020,7 @@ cmd specifies a command to exec. Valid commands are:
10251020
(connect session))
10261021
(let [[^PipedInputStream in
10271022
^PipedOutputStream send] (streams-for-in)
1028-
cmd (format "scp %s -t %s" (:remote-flags opts "") remote-path)
1023+
cmd (format "scp %s %s -t %s" (:remote-flags opts "") (if recursive "-r" "") remote-path)
10291024
_ (logging/tracef "scp-to: %s" cmd)
10301025
{:keys [^ChannelExec channel ^PipedInputStream out-stream]}
10311026
(ssh-exec session cmd in :stream opts)
@@ -1084,8 +1079,9 @@ cmd specifies a command to exec. Valid commands are:
10841079
(->>
10851080
(select-keys opts [:recursive :preserve])
10861081
(filter val)
1087-
(map (fn [k v] (k flags))))))
1082+
(map (comp flags key)))))
10881083
(string/join " " remote-paths))
1084+
_ (println cmd)
10891085
_ (logging/tracef "scp-from: %s" cmd)
10901086
{:keys [^ChannelExec channel
10911087
^PipedInputStream out-stream]}

test/clj_ssh/ssh_test.clj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,8 @@
616616
(testing ":out :stream"
617617
(let [proc (ssh s {:cmd "ls" :out :stream :pty true})]
618618
(is (> (count (slurp (:out-stream proc))) 1) ":out-stream")
619+
(while (connected-channel? (:channel proc))
620+
(Thread/sleep 100))
619621
(is (not (connected-channel? (:channel proc)))
620622
":channel not connected")
621623
(is (zero? (exit-status (:channel proc)))
@@ -628,6 +630,8 @@
628630
(testing ":out stream"
629631
(let [proc (ssh s {:in "ls" :out :stream})]
630632
(is (> (count (slurp (:out-stream proc))) 1) ":out-stream")
633+
(while (connected-channel? (:channel proc))
634+
(Thread/sleep 100))
631635
(is (not (connected-channel? (:channel proc)))
632636
":channel not connected")
633637
(is (zero? (exit-status (:channel proc)))

0 commit comments

Comments
 (0)