]> git.e2factory.org Git - e2factory.git/commitdiff
Improve read_line doc and return a sensible error message
authorTobias Ulmer <tu@emlix.com>
Wed, 6 Feb 2013 19:25:52 +0000 (20:25 +0100)
committerTobias Ulmer <tu@emlix.com>
Tue, 26 Feb 2013 18:07:15 +0000 (19:07 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/e2lib.lua

index 9da2cb8c7993fe777a61d2c510c29c5d7a948a40..3d38bb68b87fbba51162b8f418f50a0d52ae30e0 100644 (file)
@@ -742,19 +742,24 @@ function e2lib.howtounpack(physpath, virtpath, destdir)
 end
 
 --- Read the first line from the given file and return it.
+-- Beware that end of file is considered an error.
 -- @param path Path to file (string).
--- @return The first line or nil on error.
+-- @return The first line or false on error.
 -- @return Error object on failure.
 function e2lib.read_line(path)
     local f, msg = io.open(path)
     if not f then
-        return nil, err.new("%s", msg)
+        return false, err.new("%s: %s", path, msg)
     end
     local l, msg = f:read("*l")
     if not l then
-        return nil, err.new("%s", msg)
+        if not msg then
+            msg = "end of file"
+        end
+
+        f:close()
+        return false, err.new("%s: %s", path, msg)
     end
-    f:close()
     return l
 end