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_checkFindExec3 = verify checkFindExec "find / -execdir cat {} | grep lol +"
|
||||||
prop_checkFindExec4 = verifyNot checkFindExec "find / -name '*.php' -exec foo {} +"
|
prop_checkFindExec4 = verifyNot checkFindExec "find / -name '*.php' -exec foo {} +"
|
||||||
prop_checkFindExec5 = verifyNot checkFindExec "find / -execdir bash -c 'a && b' \\;"
|
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 \\;"
|
||||||
let wordId = getId $ last t in
|
checkFindExec (T_SimpleCommand _ _ t@(h:r)) | h `isCommand` "find" = do
|
||||||
err wordId "Missing ';' or + terminating -exec. You can't use |/||/&&, and ';' has to be a separate, quoted argument."
|
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
|
where
|
||||||
isBrokenFind (w:r) = w `isCommand` "find" && broken r False
|
broken [] v = return v
|
||||||
isBrokenFind _ = False
|
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
|
||||||
|
|
||||||
broken [] v = v
|
shouldWarn x =
|
||||||
broken (w:r) v = case getLiteralString w of
|
case x of
|
||||||
Just "-exec" -> broken r True
|
T_DollarExpansion _ _ -> True
|
||||||
Just "-execdir" -> broken r True
|
T_Backticked _ _ -> True
|
||||||
Just "+" -> broken r False
|
T_Glob _ _ -> True
|
||||||
Just ";" -> broken r False
|
T_Extglob _ _ _ -> True
|
||||||
_ -> broken r v
|
_ -> 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 ()
|
checkFindExec _ = return ()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue