Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Jan 2021 17:24:07 +0000 (UTC)
From:      Baptiste Daroussin <bapt@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r563097 - head/Keywords
Message-ID:  <202101271724.10RHO7u2036517@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bapt
Date: Wed Jan 27 17:24:07 2021
New Revision: 563097
URL: https://svnweb.freebsd.org/changeset/ports/563097

Log:
  Add error checks to @shell
  
  Check errors from Lua io.* library calls to make it show useful error messages
  when they do occur instead of ("attempt to index a nil value")
  
  Submitted by:	RhToad (in IRC) <andrew@tao173.riddles.org.uk>
  Differential Revision:	https://reviews.freebsd.org/D27154

Modified:
  head/Keywords/shell.ucl

Modified: head/Keywords/shell.ucl
==============================================================================
--- head/Keywords/shell.ucl	Wed Jan 27 17:20:42 2021	(r563096)
+++ head/Keywords/shell.ucl	Wed Jan 27 17:24:07 2021	(r563097)
@@ -10,7 +10,7 @@
 actions: [file]
 post-install-lua: <<EOD
   shell_path = pkg.prefixed_path("%@")
-  shell = io.open("/etc/shells", "r+")
+  shell = assert(io.open("/etc/shells", "r+"))
   while true do
     line = shell:read()
     if line == nil then break end
@@ -20,14 +20,14 @@ post-install-lua: <<EOD
       return
     end
   end
-  shell:write(shell_path .. "\n")
-  shell:close()
+  assert(shell:write(shell_path .. "\n"))
+  assert(shell:close())
 EOD
 pre-deinstall-lua: <<EOD
   shell_path = pkg.prefixed_path("%@")
   shellsbuf = ""
   shells_path = "/etc/shells"
-  shell = io.open(shells_path, "r+")
+  shell = assert(io.open(shells_path, "r+"))
   found = false
   while true do
     line = shell:read()
@@ -38,10 +38,10 @@ pre-deinstall-lua: <<EOD
       shellsbuf = shellsbuf .. line .. "\n"
     end
   end
-  shell:close()
+  assert(shell:close())
   if found then
-    shell = io.open(shells_path, "w+")
-    shell:write(shellsbuf)
-    shell:close()
+    shell = assert(io.open(shells_path, "w+"))
+    assert(shell:write(shellsbuf))
+    assert(shell:close())
   end
 EOD



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202101271724.10RHO7u2036517>