modules/luci-mod-failsafe: Fix nil file descriptor error
[project/luci.git] / modules / luci-mod-failsafe / luasrc / controller / failsafe / failsafe.lua
index 13bc6e5..60caadb 100644 (file)
@@ -1,5 +1,5 @@
 -- Copyright 2008 Steven Barth <steven@midlink.org>
--- Copyright 2008-2011 Jo-Philipp Wich <xm@subsignal.org>
+-- Copyright 2008-2011 Jo-Philipp Wich <jow@openwrt.org>
 -- Copyright 2012 Daniel Golle <dgolle@allnet.de>
 -- Licensed to the public under the Apache License 2.0.
 
@@ -84,11 +84,13 @@ function action_flashops()
                                        fp = io.open(image_tmp, "w")
                                end
                        end
-                       if chunk then
-                               fp:write(chunk)
-                       end
-                       if eof then
-                               fp:close()
+                       if fp then
+                               if chunk then
+                                       fp:write(chunk)
+                               end
+                               if eof then
+                                       fp:close()
+                               end
                        end
                end
        )