src/Pure/General/ssh.scala
changeset 80217 e0606fb415d2
parent 80216 3a8898007038
child 80218 875968a3b2f9
equal deleted inserted replaced
80216:3a8898007038 80217:e0606fb415d2
   319       put_file(path, Bytes.write(_, bytes))
   319       put_file(path, Bytes.write(_, bytes))
   320     override def write(path: Path, text: String): Unit =
   320     override def write(path: Path, text: String): Unit =
   321       put_file(path, File.write(_, text))
   321       put_file(path, File.write(_, text))
   322 
   322 
   323 
   323 
   324     /* tmp dirs */
   324     /* tmp dirs and files */
   325 
   325 
   326     override def rm_tree(dir: Path): Unit =
   326     override def rm_tree(dir: Path): Unit =
   327       execute("rm -r -f " + bash_path(dir)).check
   327       execute("rm -r -f " + bash_path(dir)).check
   328 
   328 
   329     override def tmp_dir(): Path =
   329     override def tmp_dir(): Path =
   330       Path.explode(execute("mktemp -d /tmp/ssh-XXXXXXXXXXXX").check.out)
   330       Path.explode(execute("mktemp -d /tmp/ssh-XXXXXXXXXXXX").check.out)
       
   331 
       
   332     override def tmp_file(name: String, ext: String = ""): Path = {
       
   333       val file_name = name + "-XXXXXXXXXXXX" + if_proper(ext, "." + ext)
       
   334       Path.explode(execute("mktemp /tmp/" + Bash.string(file_name)).check.out)
       
   335     }
   331 
   336 
   332     override def with_tmp_dir[A](body: Path => A): A = {
   337     override def with_tmp_dir[A](body: Path => A): A = {
   333       val path = tmp_dir()
   338       val path = tmp_dir()
   334       try { body(path) } finally { rm_tree(path) }
   339       try { body(path) } finally { rm_tree(path) }
       
   340     }
       
   341 
       
   342     override def with_tmp_file[A](name: String, ext: String = "")(body: Path => A): A = {
       
   343       val path = tmp_file(name, ext = ext)
       
   344       try { body(path) } finally { delete(path) }
   335     }
   345     }
   336 
   346 
   337 
   347 
   338     /* open server on remote host */
   348     /* open server on remote host */
   339 
   349 
   490       File.set_executable(path, reset = reset)
   500       File.set_executable(path, reset = reset)
   491     def make_directory(path: Path): Path = Isabelle_System.make_directory(path)
   501     def make_directory(path: Path): Path = Isabelle_System.make_directory(path)
   492     def rm_tree(dir: Path): Unit = Isabelle_System.rm_tree(dir)
   502     def rm_tree(dir: Path): Unit = Isabelle_System.rm_tree(dir)
   493     def tmp_dir(): Path = File.path(Isabelle_System.tmp_dir("tmp"))
   503     def tmp_dir(): Path = File.path(Isabelle_System.tmp_dir("tmp"))
   494     def with_tmp_dir[A](body: Path => A): A = Isabelle_System.with_tmp_dir("tmp")(body)
   504     def with_tmp_dir[A](body: Path => A): A = Isabelle_System.with_tmp_dir("tmp")(body)
       
   505     def tmp_file(name: String, ext: String = ""): Path =
       
   506       File.path(Isabelle_System.tmp_file(name, ext = ext))
       
   507     def with_tmp_file[A](name: String, ext: String = "")(body: Path => A): A =
       
   508       Isabelle_System.with_tmp_file(name, ext = ext)(body)
   495     def read_dir(path: Path): List[String] = File.read_dir(path)
   509     def read_dir(path: Path): List[String] = File.read_dir(path)
   496     def copy_file(path1: Path, path2: Path): Unit = Isabelle_System.copy_file(path1, path2)
   510     def copy_file(path1: Path, path2: Path): Unit = Isabelle_System.copy_file(path1, path2)
   497     def read_file(path1: Path, path2: Path): Unit = Isabelle_System.copy_file(path1, path2)
   511     def read_file(path1: Path, path2: Path): Unit = Isabelle_System.copy_file(path1, path2)
   498     def read_bytes(path: Path): Bytes = Bytes.read(path)
   512     def read_bytes(path: Path): Bytes = Bytes.read(path)
   499     def read(path: Path): String = File.read(path)
   513     def read(path: Path): String = File.read(path)