Make an empty file count as having zero lines. b=412440 r=dolske
authormats.palmgren@bredband.net
Sun, 20 Jan 2008 15:02:07 -0800
changeset 10479 96e2472ca7271bbb22061343bfd95f181d62b764
parent 10478 f81f41a29655138edbfaed9299dcf3250f93986a
child 10480 ed472eabbe418df71352a8ee42984caafecc8427
push id1
push userbsmedberg@mozilla.com
push dateThu, 20 Mar 2008 16:49:24 +0000
treeherderautoland@61007906a1f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdolske
bugs412440
milestone1.9b3pre
Make an empty file count as having zero lines. b=412440 r=dolske
toolkit/components/passwordmgr/test/unit/head_storage_legacy_1.js
--- a/toolkit/components/passwordmgr/test/unit/head_storage_legacy_1.js
+++ b/toolkit/components/passwordmgr/test/unit/head_storage_legacy_1.js
@@ -138,25 +138,27 @@ const LoginTest = {
    *
    * Counts the number of lines in the specified file.
    */
   countLinesInFile : function (aPathName,  aFileName) {
     var inputFile  = Cc["@mozilla.org/file/local;1"].
                      createInstance(Ci.nsILocalFile);
     inputFile.initWithPath(aPathName);
     inputFile.append(aFileName);
+    if (inputFile.fileSize == 0)
+      return 0;
 
     var inputStream = Cc["@mozilla.org/network/file-input-stream;1"].
                       createInstance(Ci.nsIFileInputStream);
     // init the stream as RD_ONLY, -1 == default permissions.
     inputStream.init(inputFile, 0x01, -1, null);
     var lineStream = inputStream.QueryInterface(Ci.nsILineInputStream);
 
     var line = { value : null };
-    var lineCount = 1;
+    var lineCount = 1; // Empty files were dealt with above.
     while (lineStream.readLine(line)) 
         lineCount++;
 
     return lineCount;
   }
 
 };