Skip to content

Commit

Permalink
Fix differentiate incomplete/uknown in symbolic utilities
Browse files Browse the repository at this point in the history
Fixup 40af29f (Differentiate error/incomplete/unknown in
symbolic utilities)
  • Loading branch information
benozol committed Feb 25, 2020
1 parent 631e18e commit ddd4f64
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/symbolic/symbolicUtility.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ module MakeInterpreter (Filesystem: FILESYSTEM) = struct
match !Options.unknown_behaviour with
| Exception -> raise (Errors.Unknown_behaviour (utility, msg))
| Incomplete -> incomplete ~utility msg
| Error -> error ~utility "not found"
| Error -> error ~utility msg

let table : (string, utility_context -> utility) Hashtbl.t =
let table = Hashtbl.create 10 in
Expand Down
6 changes: 5 additions & 1 deletion src/symbolic/utilities/cp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,13 @@ let interprete ctx : utility =
let e = ref None in
let r = ref false in
let i = ref false in
let a = ref false in
let args_rev = ref [] in
List.iter
(function
| "-H" | "-L" | "-f" | "-p" | "-P" -> () (* Option ignored *)
| "-i" -> i := true
| "-a" -> a := true
| "-r" | "-R" -> r := true
| arg ->
if String.length arg > 0 && arg.[0] = '-' && !e = None then
Expand All @@ -223,9 +225,11 @@ let interprete ctx : utility =
ctx.args;
if !i then
error ~utility:"cp" "option `-i` forbidden"
else if !a then
incomplete ~utility:"cp" "option -a"
else
match !e with
| Some arg -> error ~utility:"cp" ("unknown argument: " ^ arg)
| Some arg -> unknown ~utility:"cp" ("unknown argument: " ^ arg)
| None -> (
let args = List.rev !args_rev in
match args with
Expand Down
2 changes: 1 addition & 1 deletion src/symbolic/utilities/dpkg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ let interprete ctx =
(* TODO: return error state *)
error ~utility "no argument found"
| arg :: _ ->
incomplete ~utility ("unsupported argument: " ^ arg)
unknown ~utility ("argument: " ^ arg)
in
aux ctx.args
2 changes: 1 addition & 1 deletion src/symbolic/utilities/dpkgMaintscriptHelper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ let interprete ctx =
| "dir_to_symlink" ->
dir_to_symlink {ctx with args = List.tl args}
scriptarg1 scriptarg2 dms_package default_package dms_name
| _ -> unknown ~utility:"dpkg-maintscript-helper" ("unknown subcommand: " ^subcmd)
| _ -> unknown ~utility:"dpkg-maintscript-helper" ("subcommand: " ^subcmd)
with
| NoDashDash ->
error ~utility:("dpkg-maintscript-helper " ^ subcmd) "missing -- separator"
Expand Down
2 changes: 1 addition & 1 deletion src/symbolic/utilities/mkdir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ let interp_mkdir1 cwd path_str =
]

let interprete parents ctx args : utility =
if parents then incomplete ~utility:name "-p" else
if parents then incomplete ~utility:name "option -p" else
multiple_times (interp_mkdir1 ctx.cwd) args

let interprete ctx : utility =
Expand Down
18 changes: 12 additions & 6 deletions src/symbolic/utilities/mv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ let name = "mv"
let interp_rename ctx src dstpath : utility =
let qsrc = Path.from_string src in
let qdst = Path.from_string dstpath in
specification_cases @@
match Path.split_last qsrc, Path.split_last qdst with
match Path.split_last qsrc, Path.split_last qdst with
| (None, _) ->
[error_case ~descr:"mv: invalid source path ''" noop]
specification_cases [
error_case ~descr:"mv: invalid source path ''" noop
]
| (_, None) ->
[error_case ~descr:"mv: invalid destination path ''" noop]
specification_cases [
error_case ~descr:"mv: invalid destination path ''" noop
]
| (Some (_, (Here|Up)), _) | (_, Some(_, (Here|Up))) ->
[error_case ~descr:"mv: paths end in . or .." noop]
specification_cases [
error_case ~descr:"mv: paths end in . or .." noop
]
| (Some (qs, Down fs), Some (qd, Down fd)) ->
let unconditional_cases = [
error_case
Expand Down Expand Up @@ -204,6 +209,7 @@ let interp_rename ctx src dstpath : utility =
end
]
in
specification_cases @@
List.concat [ unconditional_cases; ancestor_case ; slash_case ]


Expand Down Expand Up @@ -239,7 +245,7 @@ let interprete ctx : utility =
error ~utility:"mv" "option `-i` forbidden"
else
match !e with
| Some arg -> error ~utility:"mv" ("unknown argument: " ^ arg)
| Some arg -> unknown ~utility:"mv" ("unknown argument: " ^ arg)
| None -> (
let args = List.rev !args_rev in
match args with
Expand Down
11 changes: 7 additions & 4 deletions src/symbolic/utilities/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,21 @@ let rec interp_test_expr cwd e : utility =
| Unary("-z",arg) -> interp_test_z arg
| Binary ("=",a1,a2) -> interp_test_string_equal a1 a2
| Binary ("!=",a1,a2) -> interp_test_string_notequal a1 a2
| Binary ("-eq"|"-ne"|"-gt"|"-ge"|"-lt"|"-le" as opt,_,_) ->
incomplete ~utility:name ("option "^opt)
| Unary(op,_) ->
unknown ~utility:name ("unsupported unary operator: " ^ op)
(* The Unary cases above are complete, everything else is an error *)
error ~utility:name ("unsupported unary operator: " ^ op)
| And(e1,e2) ->
uand (interp_test_expr cwd e1) (interp_test_expr cwd e2)
| Or(e1,e2) ->
uor (interp_test_expr cwd e1) (interp_test_expr cwd e2)
| Not(e1) -> uneg (interp_test_expr cwd e1)
| Binary (op,_e1,_e2) ->
unknown ~utility:name ("unsupported binary operator: " ^ op)
(* The Binary cases above are complete, everything else is an error *)
error ~utility:name ("unknown binary operator: " ^ op)
| Single arg ->
unknown ~utility:name ("unsupported single argument: " ^ arg)
)
incomplete ~utility:name ("unsupported single argument: " ^ arg))

let interpret ~bracket ctx : utility =
match Morsmall_utilities.TestParser.parse ~bracket ctx.args with
Expand Down
2 changes: 1 addition & 1 deletion src/symbolic/utilities/updateAlternatives.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ let interprete ctx =
| "--quiet" :: rem->
fun st -> aux rem (print_utility_trace (name ^ ": ignored option --quiet") st)
| arg :: _ ->
error ~utility:name ("unsupported argument: " ^ arg)
unknown ~utility:name ("unsupported argument: " ^ arg)
in
aux ctx.args

0 comments on commit ddd4f64

Please sign in to comment.