X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=modules%2Fluci-mod-failsafe%2Fluasrc%2Fcontroller%2Ffailsafe%2Ffailsafe.lua;h=60caadb4b1fc498163dbcb8325a28f3b619fc2a8;hp=db4bda6605492381e85eb15d92d3d497fd843441;hb=a16654b12130d636b4e0f81839a26f5821619baa;hpb=1bb4822dca6113f73e3bc89e2acf15935e6f8e92 diff --git a/modules/luci-mod-failsafe/luasrc/controller/failsafe/failsafe.lua b/modules/luci-mod-failsafe/luasrc/controller/failsafe/failsafe.lua index db4bda660..60caadb4b 100644 --- a/modules/luci-mod-failsafe/luasrc/controller/failsafe/failsafe.lua +++ b/modules/luci-mod-failsafe/luasrc/controller/failsafe/failsafe.lua @@ -1,18 +1,7 @@ ---[[ -LuCI - Lua Configuration Interface - -Copyright 2008 Steven Barth -Copyright 2008-2011 Jo-Philipp Wich -Copyright 2012 Daniel Golle - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -$Id$ -]]-- +-- Copyright 2008 Steven Barth +-- Copyright 2008-2011 Jo-Philipp Wich +-- Copyright 2012 Daniel Golle +-- Licensed to the public under the Apache License 2.0. module("luci.controller.failsafe.failsafe", package.seeall) @@ -43,9 +32,9 @@ end function action_flashops() local sys = require "luci.sys" - local fs = require "luci.fs" + local fs = require "nixio.fs" - local upgrade_avail = nixio.fs.access("/lib/upgrade/platform.sh") + local upgrade_avail = fs.access("/lib/upgrade/platform.sh") local reset_avail = os.execute([[grep '"rootfs_data"' /proc/mtd >/dev/null 2>&1]]) == 0 local image_tmp = "/tmp/firmware.img" @@ -66,7 +55,7 @@ function action_flashops() local function storage_size() local size = 0 - if nixio.fs.access("/proc/mtd") then + if fs.access("/proc/mtd") then for l in io.lines("/proc/mtd") do local d, s, e, n = l:match('^([^%s]+)%s+([^%s]+)%s+([^%s]+)%s+"([^%s]+)"') if n == "linux" or n == "firmware" then @@ -74,7 +63,7 @@ function action_flashops() break end end - elseif nixio.fs.access("/proc/partitions") then + elseif fs.access("/proc/partitions") then for l in io.lines("/proc/partitions") do local x, y, b, n = l:match('^%s*(%d+)%s+(%d+)%s+([^%s]+)%s+([^%s]+)') if b and n and not n:match('[0-9]') then @@ -95,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 ) @@ -114,11 +105,11 @@ function action_flashops() luci.template.render("failsafe/upgrade", { checksum = image_checksum(), storage = storage_size(), - size = nixio.fs.stat(image_tmp).size, + size = (fs.stat(image_tmp, "size") or 0), keep = false }) else - nixio.fs.unlink(image_tmp) + fs.unlink(image_tmp) luci.template.render("failsafe/flashops", { reset_avail = reset_avail, upgrade_avail = upgrade_avail,