Added warning for find . -execdir rm *.jpg \;
This commit is contained in:
parent
6402f7f4a3
commit
1fb3380e68
|
@ -286,21 +286,39 @@ prop_checkFindExec2 = verify checkFindExec "find / -exec touch {} && ls {} \\;"
|
|||
prop_checkFindExec3 = verify checkFindExec "find / -execdir cat {} | grep lol +"
|
||||
prop_checkFindExec4 = verifyNot checkFindExec "find / -name '*.php' -exec foo {} +"
|
||||
prop_checkFindExec5 = verifyNot checkFindExec "find / -execdir bash -c 'a && b' \\;"
|
||||
checkFindExec (T_SimpleCommand _ _ t) | isBrokenFind t =
|
||||
prop_checkFindExec6 = verify checkFindExec "find / -type d -execdir rm *.jpg \\;"
|
||||
checkFindExec (T_SimpleCommand _ _ t@(h:r)) | h `isCommand` "find" = do
|
||||
c <- broken r False
|
||||
when c $ do
|
||||
let wordId = getId $ last t in
|
||||
err wordId "Missing ';' or + terminating -exec. You can't use |/||/&&, and ';' has to be a separate, quoted argument."
|
||||
|
||||
where
|
||||
isBrokenFind (w:r) = w `isCommand` "find" && broken r False
|
||||
isBrokenFind _ = False
|
||||
|
||||
broken [] v = v
|
||||
broken (w:r) v = case getLiteralString w of
|
||||
broken [] v = return v
|
||||
broken (w:r) v = do
|
||||
when v $ (mapM_ warnFor $ fromWord w)
|
||||
case getLiteralString w of
|
||||
Just "-exec" -> broken r True
|
||||
Just "-execdir" -> broken r True
|
||||
Just "+" -> broken r False
|
||||
Just ";" -> broken r False
|
||||
_ -> broken r v
|
||||
|
||||
shouldWarn x =
|
||||
case x of
|
||||
T_DollarExpansion _ _ -> True
|
||||
T_Backticked _ _ -> True
|
||||
T_Glob _ _ -> True
|
||||
T_Extglob _ _ _ -> True
|
||||
_ -> False
|
||||
|
||||
warnFor x =
|
||||
if shouldWarn x
|
||||
then info (getId x) "This will expand once before find runs, not per file found."
|
||||
else return ()
|
||||
|
||||
fromWord (T_NormalWord _ l) = l
|
||||
fromWord _ = []
|
||||
checkFindExec _ = return ()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue