X-Git-Url: https://git.distorted.org.uk/~mdw/tripe-android/blobdiff_plain/04a5abaece151705e9bd7026653f79938a7a2fbc..a5ec891a1f3cbe4ae9aad5d2252f39b483ed543e:/tar.scala diff --git a/tar.scala b/tar.scala index 5f20b0a..30a3a4a 100644 --- a/tar.scala +++ b/tar.scala @@ -32,6 +32,9 @@ import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.util.Date; +import sys.FileInfo; +import sys.FileInfo.{Value, FIFO, CHR, DIR, BLK, REG, LNK, HDLNK, UNK}; + /*----- Main code ---------------------------------------------------------*/ class TarFormatError(msg: String) extends Exception(msg); @@ -45,7 +48,7 @@ trait TarEntry { /* Basic facts about the entry. */ def name: String; def size: Long; - def typ: Char; + def rawtyp: Char; def mode: Int; def mtime: Date; def uid: Int; @@ -53,17 +56,28 @@ trait TarEntry { def link: String; /* Type predicates (intentionally like `FileInfo'). */ - def isfifo: Boolean = typ == '6'; - def ischr: Boolean = typ == '3'; - def isdir: Boolean = typ == '5'; - def isblk: Boolean = typ == '4'; - def isreg: Boolean = typ match { + def isfifo: Boolean = rawtyp == '6'; + def ischr: Boolean = rawtyp == '3'; + def isdir: Boolean = rawtyp == '5'; + def isblk: Boolean = rawtyp == '4'; + def isreg: Boolean = rawtyp match { case 0 | '0' | '7' => true case _ => false } - def islnk: Boolean = typ == '2'; + def islnk: Boolean = rawtyp == '2'; def issock: Boolean = false; - def ishardlink: Boolean = typ == '1'; + def ishardlink: Boolean = rawtyp == '1'; + + def typ: FileInfo.Value = rawtyp match { + case 0 | '0' | '7' => REG + case '1' => HDLNK + case '2' => LNK + case '3' => CHR + case '4' => BLK + case '5' => DIR + case '6' => FIFO + case _ => UNK + } def verbose: String = { /* Encode information about this tar header as a string. */ @@ -71,7 +85,7 @@ trait TarEntry { val sb = new StringBuilder; /* First, the type code. */ - sb += (typ match { + sb += (rawtyp match { case 0 | '0' | '7' => '-' case '1' => 'L' case '2' => 'l' @@ -274,7 +288,7 @@ class TarFile(in: InputStream) } private[this] class Entry(val name: String, val size: Long, - val typ: Char, val mode: Int, + val rawtyp: Char, val mode: Int, val mtime: Date, val uid: Int, val gid: Int, val link: String,