src/Pure/General/file.scala
changeset 64775 dd3797f1e0d6
parent 64760 8c1557308eb5
child 64932 89c0896a19ad
equal deleted inserted replaced
64770:1ddc262514b8 64775:dd3797f1e0d6
    11   OutputStream, InputStream, FileInputStream, BufferedInputStream, BufferedReader,
    11   OutputStream, InputStream, FileInputStream, BufferedInputStream, BufferedReader,
    12   InputStreamReader, File => JFile, IOException}
    12   InputStreamReader, File => JFile, IOException}
    13 import java.nio.file.{StandardOpenOption, StandardCopyOption, Path => JPath,
    13 import java.nio.file.{StandardOpenOption, StandardCopyOption, Path => JPath,
    14   Files, SimpleFileVisitor, FileVisitResult}
    14   Files, SimpleFileVisitor, FileVisitResult}
    15 import java.nio.file.attribute.BasicFileAttributes
    15 import java.nio.file.attribute.BasicFileAttributes
    16 import java.net.{URL, URLDecoder, MalformedURLException}
    16 import java.net.{URL, MalformedURLException}
    17 import java.util.zip.{GZIPInputStream, GZIPOutputStream}
    17 import java.util.zip.{GZIPInputStream, GZIPOutputStream}
    18 import java.util.regex.Pattern
    18 import java.util.regex.Pattern
    19 
    19 
    20 import org.tukaani.xz.{XZInputStream, XZOutputStream}
    20 import org.tukaani.xz.{XZInputStream, XZOutputStream}
    21 
    21 
    31 
    31 
    32   def standard_path(platform_path: String): String =
    32   def standard_path(platform_path: String): String =
    33     if (Platform.is_windows) {
    33     if (Platform.is_windows) {
    34       val Platform_Root = new Regex("(?i)" +
    34       val Platform_Root = new Regex("(?i)" +
    35         Pattern.quote(Isabelle_System.cygwin_root()) + """(?:\\+|\z)(.*)""")
    35         Pattern.quote(Isabelle_System.cygwin_root()) + """(?:\\+|\z)(.*)""")
    36       val Drive = new Regex("""\\?([a-zA-Z]):\\*(.*)""")
    36       val Drive = new Regex("""([a-zA-Z]):\\*(.*)""")
    37 
    37 
    38       platform_path.replace('/', '\\') match {
    38       platform_path.replace('/', '\\') match {
    39         case Platform_Root(rest) => "/" + rest.replace('\\', '/')
    39         case Platform_Root(rest) => "/" + rest.replace('\\', '/')
    40         case Drive(letter, rest) =>
    40         case Drive(letter, rest) =>
    41           "/cygdrive/" + Word.lowercase(letter) +
    41           "/cygdrive/" + Word.lowercase(letter) +
    51   def pwd(): Path = path(Path.current.file.toPath.toAbsolutePath.toFile)
    51   def pwd(): Path = path(Path.current.file.toPath.toAbsolutePath.toFile)
    52 
    52 
    53   def standard_url(name: String): String =
    53   def standard_url(name: String): String =
    54     try {
    54     try {
    55       val url = new URL(name)
    55       val url = new URL(name)
    56       if (url.getProtocol == "file")
    56       if (url.getProtocol == "file" && Url.is_wellformed_file(name))
    57         standard_path(URLDecoder.decode(url.getPath, UTF8.charset_name))
    57         standard_path(Url.parse_file(name))
    58       else name
    58       else name
    59     }
    59     }
    60     catch { case _: MalformedURLException => standard_path(name) }
    60     catch { case _: MalformedURLException => standard_path(name) }
    61 
    61 
    62 
    62