support for remote tmp dirs;
authorwenzelm
Tue, 11 Oct 2016 09:32:56 +0200
changeset 64137 e9b3d9c1bc5a
parent 64136 7c5191489457
child 64138 cf0c8c5782af
support for remote tmp dirs;
src/Pure/General/ssh.scala
--- a/src/Pure/General/ssh.scala	Mon Oct 10 22:20:00 2016 +0200
+++ b/src/Pure/General/ssh.scala	Tue Oct 11 09:32:56 2016 +0200
@@ -277,6 +277,21 @@
       val channel = session.openChannel(kind).asInstanceOf[ChannelSftp]
       new Sftp(this, kind, options, channel)
     }
+
+
+    /* tmp dirs */
+
+    def rm_tree(remote_dir: String): Unit =
+      execute("rm -r -f " + File.bash_string(remote_dir)).check
+
+    def tmp_dir(): String =
+      execute("mktemp -d -t tmp.XXXXXXXXXX").check.out
+
+    def with_tmp_dir[A](body: String => A): A =
+    {
+      val remote_dir = tmp_dir()
+      try { body(remote_dir) } finally { rm_tree(remote_dir) }
+    }
   }
 }