Skip to content

Commit

Permalink
Fix more warnings from static code analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
poelzi committed Nov 11, 2022
1 parent 945b57d commit 5096f27
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 34 deletions.
1 change: 1 addition & 0 deletions default-rsync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ rsync.prepare = function

crsync._computed = { true }

--- @type any
local computed = crsync._computed

local computedN = 2
Expand Down
1 change: 1 addition & 0 deletions default.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ then
error( 'default already loaded' )
end

--- @diagnostic disable-next-line: lowercase-global
default = { }


Expand Down
4 changes: 2 additions & 2 deletions examples/lbash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/lecho.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions examples/lgforce.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/limagemagic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
--
local formats = { jpg=true, gif=true, png=true, }

convert = {
local convert = {
delay = 0,

maxProcesses = 99,
Expand Down
2 changes: 1 addition & 1 deletion examples/ls3.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
--
-- Author: Daniel Miranda <danielkza2@gmail.com>
--
s3 = {}
local s3 = {}

s3.checkgauge = {
onCreate = false,
Expand Down
9 changes: 5 additions & 4 deletions examples/lsayirc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/churn-direct.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/churn-rsync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/churn-rsyncssh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/cron-rsync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 );

Expand Down
4 changes: 2 additions & 2 deletions tests/exclude-rsync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 );

Expand Down
4 changes: 2 additions & 2 deletions tests/exclude-rsyncssh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 )

Expand Down
4 changes: 2 additions & 2 deletions tests/filter-rsync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 );

Expand Down
6 changes: 3 additions & 3 deletions tests/l4rsyncdata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ then
end
cwriteln( 'starting Lsyncd' )

logs = { }
local logs = { }
local pid =
spawn(
'./lsyncd',
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/schedule.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 8 additions & 2 deletions tests/testlib.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
--- @diagnostic disable: lowercase-global, need-check-nil

-- common testing environment
posix = require( 'posix' )
string = require( 'string' )
Expand All @@ -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

Expand Down Expand Up @@ -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 )
Expand All @@ -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( )
Expand Down

0 comments on commit 5096f27

Please sign in to comment.