keys.scala, etc.: Make merging public keys have a progress bar.
[tripe-android] / tar.scala
index 5f20b0a..986eeaa 100644 (file)
--- a/tar.scala
+++ b/tar.scala
@@ -32,6 +32,11 @@ 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};
+
+import Implicits.truish;
+
 /*----- Main code ---------------------------------------------------------*/
 
 class TarFormatError(msg: String) extends Exception(msg);
@@ -45,7 +50,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 +58,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 +87,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'
@@ -84,12 +100,10 @@ trait TarEntry {
 
     /* Then the permissions bits.  Ugh, the permissions bits. */
     def perm(s: Int, r: Int, w: Int, x: Int, schar: Char, Schar: Char) {
-      sb += (if ((mode&r) != 0) 'r' else '-');
-      sb += (if ((mode&w) != 0) 'w' else '-');
-      sb += (if ((mode&s) != 0)
-              if ((mode&x) != 0) schar else Schar;
-            else
-              if ((mode&x) != 0) 'x' else '-');
+      sb += (if (mode&r) 'r' else '-');
+      sb += (if (mode&w) 'w' else '-');
+      sb += (if (mode&s) { if (mode&x) schar else Schar; }
+            else { if (mode&x) 'x' else '-' });
     }
     perm(0x800, 0x100, 0x080, 0x040, 's', 'S');
     perm(0x400, 0x020, 0x010, 0x008, 's', 'S');
@@ -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,
@@ -323,7 +337,7 @@ class TarFile(in: InputStream)
       val b = hdr(i);
 
       /* See if we're done now. */
-      if (b == ' ' || b == 0) return n;
+      if (!b || b == ' ') return n;
       else if (b < '0' || b > '7')
        throw new TarFormatError(s"bad octal digit (at ${offset + off + i})");
 
@@ -393,7 +407,7 @@ class TarFile(in: InputStream)
      */
     val name = {
       val tail = string(0, 100);
-      if (!posixp || hdr(345) == 0) tail
+      if (!posixp || !hdr(345)) tail
       else {
        val prefix = string(345, 155);
        prefix + '/' + tail