Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clojure.java.io/file not working? #150

Open
tomconnors opened this issue Apr 13, 2022 · 1 comment
Open

clojure.java.io/file not working? #150

tomconnors opened this issue Apr 13, 2022 · 1 comment

Comments

@tomconnors
Copy link
Contributor

In this example, .isDirectory is wrong and .listFiles doesn't show the files in the directory.

(ns test
  (:require
   [spire.modules :as spire]
   [clojure.java.io :as io]))

(defn main []
  (spire/ssh
   {:hostname "10.10.3.250" :username "ubuntu"}
   (spire/mkdir {:path "/home/ubuntu/testdir"})
   (spire/upload {:content "test1"
                  :dest "/home/ubuntu/testdir/test1"})
   (spire/upload {:content "test2"
                  :dest "/home/ubuntu/testdir/test2"})
   (let [file (io/file "/home/ubuntu/testdir")]
     (spire/debug
      {:file file
       :isDirectory (.isDirectory file)
       :listFiles (.listFiles file)}))
   (spire/debug
    (spire/shell {:cmd "ls -lah /home/ubuntu/testdir"})))
  :ok)

(main)

Output:

% spire --version
Version: 0.1.0-alpha.18
% spire spiretest.clj
spiretest.clj:9 (spire/mkdir {:path "/home/ubuntu/testdir"}) [email protected]
spiretest.clj:10 (spire/upload {:content "test1", :dest "/home/ubuntu/testdir/test1"}) [email protected]
spiretest.clj:12 (spire/upload {:content "test2", :dest "/home/ubuntu/testdir/test2"}) [email protected]
--------- spiretest.clj:15 [email protected] (spire/debug {:file file, :isDirectory (.isDirectory file), :listFiles (.listFiles file)}) ---------
{:file #<java.io.File@389c00fc /home/ubuntu/testdir>,
 :isDirectory false,
 :listFiles nil}
--------------------------------------------------------------------------------------------------------------------------------------------------
spiretest.clj:20 (spire/shell {:cmd "ls -lah /home/ubuntu/testdir"}) [email protected]
--------- spiretest.clj:19 [email protected] (spire/debug (spire/shell {:cmd "ls -lah /home/ubuntu/testdir"})) ---------
{:err "",
 :exit 0,
 :out "total 16K\ndrwxrwxr-x  2 ubuntu ubuntu 4.0K Apr 13 21:22 .\ndrwxr-xr-x 15 ubuntu ubuntu 4.0K Apr 13 21:22 ..\n-rw-r--r--  1 ubuntu ubuntu    5 Apr 13 21:22 test1\n-rw-r--r--  1 ubuntu ubuntu    5 Apr 13 21:22 test2\n",
 :out-lines ["total 16K"
             "drwxrwxr-x  2 ubuntu ubuntu 4.0K Apr 13 21:22 ."
             "drwxr-xr-x 15 ubuntu ubuntu 4.0K Apr 13 21:22 .."
             "-rw-r--r--  1 ubuntu ubuntu    5 Apr 13 21:22 test1"
             "-rw-r--r--  1 ubuntu ubuntu    5 Apr 13 21:22 test2"],
 :result :ok}
-------------------------------------------------------------------------------------------------------------------------
:ok
@retrogradeorbit
Copy link
Member

io/file will be referring to your local host, where I assume there is no /home/ubuntu/testdir. There really should be some easy way to get that kind of remote info without invoking shell... 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants