Skip to content

Commit

Permalink
ensure upload :content works #74
Browse files Browse the repository at this point in the history
  • Loading branch information
retrogradeorbit committed Jun 3, 2020
1 parent 0a69d4d commit 9305a09
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 21 deletions.
43 changes: 29 additions & 14 deletions src/clj/spire/module/upload.clj
Original file line number Diff line number Diff line change
Expand Up @@ -230,20 +230,10 @@
)))))

;; straight single copy
(let [local-md5 (digest/md5 content)
remote-md5 (some-> (facts/on-shell
:csh (run (format "%s \"%s\"" (facts/md5) dest))
:else (run (format "%s \"%s\"" (facts/md5) dest)))
process-md5-out
first)
;; _ (println "l:" local-md5 "r:" remote-md5)
;; _ (do (println "\n\n\n"))
]
(comment (prn "local-md5:" local-md5)
(prn "remote-md5:" remote-md5))
(if content?
;; content upload
(scp-result
(when (not= local-md5 remote-md5)
(scp/scp-to session content dest
(scp/scp-content-to session content dest
:progress-fn progress-fn
:preserve preserve
:dir-mode (or dir-mode 0755)
Expand All @@ -252,7 +242,32 @@
:exec-fn exec-fn
:shell-fn shell-fn
:stdin-fn stdin-fn
)))))
))

;; file upload
(let [local-md5 (digest/md5 content)
remote-md5 (some-> (facts/on-shell
:csh (run (format "%s \"%s\"" (facts/md5) dest))
:else (run (format "%s \"%s\"" (facts/md5) dest)))
process-md5-out
first)
;; _ (println "l:" local-md5 "r:" remote-md5)
;; _ (do (println "\n\n\n"))
]
(comment (prn "local-md5:" local-md5)
(prn "remote-md5:" remote-md5))
(scp-result
(when (not= local-md5 remote-md5)
(scp/scp-to session content dest
:progress-fn progress-fn
:preserve preserve
:dir-mode (or dir-mode 0755)
:mode (or mode 0644)
:exec exec
:exec-fn exec-fn
:shell-fn shell-fn
:stdin-fn stdin-fn
))))))

passed-attrs? (or owner group dir-mode mode attrs)

Expand Down
17 changes: 10 additions & 7 deletions test/clojure/spire/module/upload_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,13 @@
{:result :changed, :attr-result {:result :changed}, :copy-result {:result :changed}}
))
(is (= (test-utils/run (format "cd '%s'; find ." path-a))
(test-utils/run (format "cd '%s'; find ." path-b))))
)



)
)
(test-utils/run (format "cd '%s'; find ." path-b)))))))

(deftest upload-content
(testing "upload :content works"
(let [dest "/tmp/spire-upload-test-content"
content "this is a test"]
(test-utils/remove-file dest)
(is (= (upload/upload {:dest dest :content content})
{:result :changed, :attr-result {:result :ok}, :copy-result {:result :changed}}))
(is (= content (slurp dest))))))

0 comments on commit 9305a09

Please sign in to comment.