Commits

Liam Staskawicz committed 29e28ea

* fix casting error in DB.profilingLevel
* formatting cleanup

Comments (0)

Files changed (2)

   private Str validateName(Str name)
   {
     invalidNameChars.each |c| {
-      if(name.containsChar(c))
+      if (name.containsChar(c))
         throw ArgErr("invalid db name - ${name} contains ${c.toChar}")
     }
     
-    if(name.isEmpty)
+    if (name.isEmpty)
       throw ArgErr("invalid db name - must not be empty")
     
     return name
   Bool authenticate(Str username, Str password)
   {
     res := command(["getnonce": 1])
-    if(!cmdOk(res))
+    if (!cmdOk(res))
       throw Err("authenticate - error retrieving nonce: ${res}")
 
     nonce := res["nonce"]
     names := Str[,]
     Collection(this, "system.namespaces").find().toList().each |v, i| {
       Str s := (v as Map)["name"]
-      if(!s.contains("system.") && !s.contains("\$"))
+      if (!s.contains("system.") && !s.contains("\$"))
         names.add(s)
     }
     return names
   **
   Int profilingLevel()
   {
-    Str:Float res := command(["profile":-1])
-    if(!cmdOk(res))
+    res := command(["profile":-1])
+    if (!cmdOk(res))
       throw MongoOpErr("""error while retrieving profiling level - ${res["err"]}""")
-    return res["was"].toInt
+    return res["was"]
   }
   
   **
   **
   Void setProfilingLevel(Int level)
   {
-    if(!(0..2).contains(level))
+    if (!(0..2).contains(level))
       throw ArgErr("invalid profiling level ${level} - must be between 0 - 2.")
     command(["profile": level])
   }
   Str? lastErr()
   {
     res := command(["getlasterror": 1])
-    if(!cmdOk(res))
+    if (!cmdOk(res))
       throw MongoOpErr("lastErr() failure - ${res}")
     return res["err"]
   }
   Str:Obj buildInfo()
   {
     res := command(["buildinfo": 1], true)
-    if(!cmdOk(res))
+    if (!cmdOk(res))
       throw MongoOpErr("""invalid buildInfo request - ${res["err"]}""")
     return res
   }
   Str:Obj validateCollection(Str coll)
   {
     res := command(["validate": name])
-    if(!cmdOk(res))
+    if (!cmdOk(res))
       throw MongoOpErr("""Error with validate command: ${res["err"]}""")
     
     result := res["result"]
-    if(result isnot Str)
+    if (result isnot Str)
       throw MongoOpErr("Error with validation data: ${res}")
     // raise "Error: invalid collection #{name}: #{doc.inspect}" if result =~ /\b(exception|corrupt)\b/i
     return res
   {
     cmd := [:] { ordered = true }
     cmd["\$eval"] = javascript
-    if(!args.isEmpty) cmd["args"] = args
+    if (!args.isEmpty) cmd["args"] = args
     doc := command(cmd)
-    if(cmdOk(doc))
+    if (cmdOk(doc))
       return doc["retval"]
     else
       throw MongoOpErr("eval failed: ${doc}")
   
   Map? command(Map cmd, Bool admin := false)
   {
-    if(cmd.keys.size > 1 && !cmd.ordered)
+    if (cmd.keys.size > 1 && !cmd.ordered)
       throw ArgErr("commands with more than one key must be ordered")
     // negative batchsize means "return the abs value specified and close the cursor" 
     Str:Obj opts := ["batchsize": -1]
-    if(admin == true) opts["admin"] = true
+    if (admin == true) opts["admin"] = true
     return collection("\$cmd").findOne(cmd, opts)
   }
   
     cmd := Str:Obj?[:] { ordered = true }
     cmd.set("deleteIndexes", coll).set("index", idx) 
     res := command(cmd)
-    if(!cmdOk(res))
+    if (!cmdOk(res))
       throw MongoOpErr("dropIndex failed: ${res}")
   }
   
   Void dropCollection(Str coll)
   {
-    if(collectionNames.contains("${name}.${coll}")) {
+    if (collectionNames.contains("${name}.${coll}")) {
       res := command(["drop":coll])
-      if(!cmdOk(res))
+      if (!cmdOk(res))
         throw MongoOpErr("drop collection failed: ${res}")
     }
   }
   Void drop()
   {
     res := command(["dropDatabase": 1])
-    if(!cmdOk(res))
+    if (!cmdOk(res))
       throw MongoOpErr("dropDatabase failed: ${res}")
   }
   
   List listDatabases()
   {
     res := command(["listDatabases": 1], true)
-    if(!cmdOk(res))
+    if (!cmdOk(res))
       throw MongoOpErr("listDatabases failed: ${res}")
     return res["databases"]
   }
     c["preserveClonedFilesOnFailure"] = preserveClonedFilesOnFailure
     c["backupOriginalFiles"] = backupOriginalFiles
     res := command(c)
-    if(!cmdOk(res))
+    if (!cmdOk(res))
       throw MongoOpErr("repairDatabase error - $res")
   }
   
     proflevel := db.profilingLevel
     verify((0..2).contains(proflevel))
     newlevel := proflevel + 1
-    if(newlevel > 2) newlevel = 0
+    if (newlevel > 2) newlevel = 0
     db.setProfilingLevel(newlevel)
     verify(newlevel == db.profilingLevel)
     db.setProfilingLevel(proflevel) // reset it