From 5096f27bbdaf2f37428f2d428aa8b1c7ed91e409 Mon Sep 17 00:00:00 2001 From: Daniel Poelzleithner Date: Fri, 11 Nov 2022 15:27:21 +0100 Subject: [PATCH] Fix more warnings from static code analysis --- default-rsync.lua | 1 + default.lua | 1 + examples/lbash.lua | 4 ++-- examples/lecho.lua | 2 +- examples/lgforce.lua | 8 ++++---- examples/limagemagic.lua | 2 +- examples/ls3.lua | 2 +- examples/lsayirc.lua | 9 +++++---- tests/churn-direct.lua | 6 +++--- tests/churn-rsync.lua | 4 ++-- tests/churn-rsyncssh.lua | 4 ++-- tests/cron-rsync.lua | 4 ++-- tests/exclude-rsync.lua | 4 ++-- tests/exclude-rsyncssh.lua | 4 ++-- tests/filter-rsync.lua | 4 ++-- tests/l4rsyncdata.lua | 6 +++--- tests/schedule.lua | 2 +- tests/testlib.lua | 10 ++++++++-- 18 files changed, 43 insertions(+), 34 deletions(-) diff --git a/default-rsync.lua b/default-rsync.lua index a0229a1..5b06cab 100644 --- a/default-rsync.lua +++ b/default-rsync.lua @@ -592,6 +592,7 @@ rsync.prepare = function crsync._computed = { true } + --- @type any local computed = crsync._computed local computedN = 2 diff --git a/default.lua b/default.lua index b8f8664..d6caa23 100644 --- a/default.lua +++ b/default.lua @@ -13,6 +13,7 @@ then error( 'default already loaded' ) end +--- @diagnostic disable-next-line: lowercase-global default = { } diff --git a/examples/lbash.lua b/examples/lbash.lua index 5226f4d..5ab5d10 100644 --- a/examples/lbash.lua +++ b/examples/lbash.lua @@ -15,12 +15,12 @@ settings { -- for testing purposes. prefix can be used to slow commands down. -- prefix = "sleep 5 && " -- -prefix = "" +local prefix = "" ----- -- for testing purposes. uses bash command to hold local dirs in sync. -- -bash = { +local bash = { delay = 0, maxProcesses = 1, diff --git a/examples/lecho.lua b/examples/lecho.lua index 4a09ce8..97a1675 100644 --- a/examples/lecho.lua +++ b/examples/lecho.lua @@ -7,7 +7,7 @@ ----- -- for testing purposes. just echos what is happening. -- -echo = { +local echo = { maxProcesses = 1, delay = 1, onStartup = "/bin/echo telling about ^source", diff --git a/examples/lgforce.lua b/examples/lgforce.lua index dd4a1cd..eedf8c8 100644 --- a/examples/lgforce.lua +++ b/examples/lgforce.lua @@ -22,12 +22,12 @@ ---- -- forces this group. -- -fgroup = "staff" +local fgroup = "staff" ----- -- script for all changes. -- -command = +local command = -- checks if the group is the one enforced and sets them if not [[ perm=`stat -c %A ^sourcePathname` @@ -59,13 +59,13 @@ fi -- the carret as first char tells Lsycnd to call a shell altough it -- starts with a slash otherwisw -- -startup = +local startup = [[^/bin/chgrp -R ]]..fgroup..[[ ^source || /bin/true && /bin/chmod -R g+rw ^source || /bin/true && /usr/bin/find ^source -type d | xargs chmod g+x ]] -gforce = { +local gforce = { maxProcesses = 99, delay = 1, onStartup = startup, diff --git a/examples/limagemagic.lua b/examples/limagemagic.lua index 1990b53..9f6d0ec 100644 --- a/examples/limagemagic.lua +++ b/examples/limagemagic.lua @@ -12,7 +12,7 @@ -- local formats = { jpg=true, gif=true, png=true, } -convert = { +local convert = { delay = 0, maxProcesses = 99, diff --git a/examples/ls3.lua b/examples/ls3.lua index bc38d7c..d1b442e 100644 --- a/examples/ls3.lua +++ b/examples/ls3.lua @@ -19,7 +19,7 @@ -- -- Author: Daniel Miranda -- -s3 = {} +local s3 = {} s3.checkgauge = { onCreate = false, diff --git a/examples/lsayirc.lua b/examples/lsayirc.lua index c9716b6..f0c7fcb 100644 --- a/examples/lsayirc.lua +++ b/examples/lsayirc.lua @@ -21,15 +21,16 @@ require("socket") -- For demo reasons, do not detach settings.nodaemon = true -hostname = "irc.freenode.org" +local hostname = "irc.freenode.org" --hostname = "127.0.0.1" -port = 6667 -nick = "lbot01" -chan = "##lfile01" +local port = 6667 +local nick = "lbot01" +local chan = "##lfile01" -- this blocks until the connection is established -- for once lets say this ok since Lsyncd didnt yet actually -- start. +--- @diagnostic disable-next-line: undefined-global local ircSocket, err = socket.connect(hostname, port) if not ircSocket then log("Error", "Cannot connect to IRC: ", err) diff --git a/tests/churn-direct.lua b/tests/churn-direct.lua index a37adea..7fb2963 100644 --- a/tests/churn-direct.lua +++ b/tests/churn-direct.lua @@ -12,7 +12,7 @@ cwriteln( '****************************************************************' ) local tdir, srcdir, trgdir = mktemps( ) -- makes some startup data -churn( srcdir, 10, init ) +churn( srcdir, 10, false ) local logs = { } --local logs = {'-log', 'Exec', '-log', 'Delay' } @@ -34,10 +34,10 @@ posix.sleep( 10 ) cwriteln( 'killing the Lsyncd daemon' ) posix.kill( pid ) -local _, exitmsg, lexitcode = posix.wait( lpid ) +local _, exitmsg, lexitcode = posix.wait( pid ) cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode ) -result, code = execute( 'diff -r ' .. srcdir .. ' ' .. trgdir ) +local result, code = execute( 'diff -r ' .. srcdir .. ' ' .. trgdir ) if result == 'exit' then diff --git a/tests/churn-rsync.lua b/tests/churn-rsync.lua index 3446be2..46a4a92 100644 --- a/tests/churn-rsync.lua +++ b/tests/churn-rsync.lua @@ -36,10 +36,10 @@ posix.sleep( 10 ) cwriteln( 'killing the Lsyncd daemon' ) posix.kill( pid ) -local _, exitmsg, lexitcode = posix.wait( lpid ) +local _, exitmsg, lexitcode = posix.wait( pid ) cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode ) -result, code = execute( 'diff -r ' .. srcdir .. ' ' .. trgdir ) +local result, code = execute( 'diff -r ' .. srcdir .. ' ' .. trgdir ) if result == 'exit' then diff --git a/tests/churn-rsyncssh.lua b/tests/churn-rsyncssh.lua index 9162edd..4f5accc 100644 --- a/tests/churn-rsyncssh.lua +++ b/tests/churn-rsyncssh.lua @@ -43,11 +43,11 @@ cwriteln( 'killing the Lsyncd daemon' ) posix.kill(pid) -local _, exitmsg, lexitcode = posix.wait( lpid ) +local _, exitmsg, lexitcode = posix.wait( pid ) cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode ) -result, code = execute( 'diff -r ' .. srcdir .. ' ' .. trgdir ) +local result, code = execute( 'diff -r ' .. srcdir .. ' ' .. trgdir ) if result == 'exit' then diff --git a/tests/cron-rsync.lua b/tests/cron-rsync.lua index 7843fd4..5118d34 100644 --- a/tests/cron-rsync.lua +++ b/tests/cron-rsync.lua @@ -132,7 +132,7 @@ cwriteln( 'waiting for Lsyncd to remove destination' ) posix.sleep( 20 ) -result, code = execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir ) +local result, code = execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir ) if result ~= 'exit' or code ~= 0 then @@ -155,7 +155,7 @@ testfiles( ) cwriteln( 'killing started Lsyncd' ) posix.kill( pid ) -local _, exitmsg, exitcode = posix.wait( lpid ) +local _, exitmsg, exitcode = posix.wait( pid ) cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', exitcode ); diff --git a/tests/exclude-rsync.lua b/tests/exclude-rsync.lua index c1d5296..af982ff 100644 --- a/tests/exclude-rsync.lua +++ b/tests/exclude-rsync.lua @@ -115,7 +115,7 @@ cwriteln( 'waiting for Lsyncd to remove destination' ) posix.sleep( 5 ) -result, code = execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir ) +local result, code = execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir ) if result ~= 'exit' or code ~= 0 then @@ -137,7 +137,7 @@ testfiles( ) cwriteln( 'killing started Lsyncd' ) posix.kill( pid ) -local _, exitmsg, exitcode = posix.wait( lpid ) +local _, exitmsg, exitcode = posix.wait( pid ) cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', exitcode ); diff --git a/tests/exclude-rsyncssh.lua b/tests/exclude-rsyncssh.lua index 483505b..d5ba714 100644 --- a/tests/exclude-rsyncssh.lua +++ b/tests/exclude-rsyncssh.lua @@ -113,7 +113,7 @@ os.execute( 'rm -rf ' .. srcdir .. '/*' ) cwriteln( 'waiting for Lsyncd to remove destination' ) posix.sleep( 5 ) -result, code = execute( 'diff -urN '..srcdir..' '..trgdir ) +local result, code = execute( 'diff -urN '..srcdir..' '..trgdir ) if result ~= 'exit' or code ~= 0 then @@ -129,7 +129,7 @@ testfiles( ) cwriteln( 'killing started Lsyncd' ) posix.kill( pid ) -local _, exitmsg, lexitcode = posix.wait( lpid ) +local _, exitmsg, lexitcode = posix.wait( pid ) cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode ) posix.sleep( 1 ) diff --git a/tests/filter-rsync.lua b/tests/filter-rsync.lua index 5a5a7b2..b97f6ad 100644 --- a/tests/filter-rsync.lua +++ b/tests/filter-rsync.lua @@ -109,7 +109,7 @@ cwriteln( 'waiting for Lsyncd to remove destination' ) posix.sleep( 5 ) -result, code = execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir ) +local result, code = execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir ) if result ~= 'exit' or code ~= 0 then @@ -131,7 +131,7 @@ testfiles( ) cwriteln( 'killing started Lsyncd' ) posix.kill( pid ) -local _, exitmsg, exitcode = posix.wait( lpid ) +local _, exitmsg, exitcode = posix.wait( pid ) cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', exitcode ); diff --git a/tests/l4rsyncdata.lua b/tests/l4rsyncdata.lua index 10820a4..bf7d57e 100644 --- a/tests/l4rsyncdata.lua +++ b/tests/l4rsyncdata.lua @@ -19,7 +19,7 @@ then end cwriteln( 'starting Lsyncd' ) -logs = { } +local logs = { } local pid = spawn( './lsyncd', @@ -55,12 +55,12 @@ posix.sleep( 10 ) cwriteln( '* killing Lsyncd' ) posix.kill( pid ) -local _, exitmsg, lexitcode = posix.wait(lpid) +local _, exitmsg, lexitcode = posix.wait(pid) cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode) posix.sleep( 1 ) cwriteln( '* differences:' ) -result, code = execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir ) +local result, code = execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir ) if result == 'exit' then diff --git a/tests/schedule.lua b/tests/schedule.lua index 143799d..3caa3dc 100644 --- a/tests/schedule.lua +++ b/tests/schedule.lua @@ -69,7 +69,7 @@ testfile( srcdir..'b' ) testfile( srcdir..'c' ) cwriteln( 'killing started Lsyncd' ) posix.kill( pid ) -local _, exitmsg, lexitcode = posix.wait( lpid ) +local _, exitmsg, lexitcode = posix.wait( pid ) cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode) posix.sleep(1); diff --git a/tests/testlib.lua b/tests/testlib.lua index 25cf1ca..ead349c 100644 --- a/tests/testlib.lua +++ b/tests/testlib.lua @@ -1,3 +1,5 @@ +--- @diagnostic disable: lowercase-global, need-check-nil + -- common testing environment posix = require( 'posix' ) string = require( 'string' ) @@ -11,6 +13,7 @@ local c0='\027[0m' -- compatibility with 5.1 if table.unpack == nil then + --- @diagnostic disable-next-line: deprecated table.unpack = unpack end @@ -46,8 +49,7 @@ end -- If environment variable 'SEED' is set, -- that one is used seed. -- -local seed = os.getenv( 'SEED') or os.time( ) - +local seed = tonumber(os.getenv( 'SEED')) or os.time( ) math.randomseed( seed ) cwriteln( 'random seed: ', seed ) @@ -61,6 +63,10 @@ function mktempd ( ) local f = io.popen( 'mktemp -td ltest.XXX', 'r' ) + if f == nil then + return error("can't create testing directory") + end + local s = f:read( '*a' ) f:close( )