Skip to content

Commit

Permalink
fix the heuristic to retrieve NAME and VERSION
Browse files Browse the repository at this point in the history
The 'OpamMisc.cut_at' test can be safely removed because 'of_filename' ends every execution paths by 'of_string_opt' (or returns 'None' without exception), and 'of_string_opt' also performs the ' ' checking.
However the semantic is changed as it fixes ocaml#216 .
  • Loading branch information
tuong committed Oct 8, 2012
1 parent ee6583e commit 54eff3f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
38 changes: 17 additions & 21 deletions src/opamPackage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,24 @@ let of_string s = match of_string_opt s with

(* XXX: this function is quite hackish, as it mainly depends on the shape the paths
built in path.ml *)
let rec of_filename f =
let of_filename f =
let f = OpamMisc.strip (OpamFilename.to_string f) in
if OpamMisc.cut_at f ' ' <> None then
None
else begin
let base = Filename.basename f in
let parent = Filename.basename (Filename.dirname f) in
match base with
| "opam" | "descr" | "url" ->
of_string_opt parent
| _ ->
if Filename.check_suffix base ".opam" then
of_string_opt (Filename.chop_suffix base ".opam")
else if Filename.check_suffix base "+opam.tar.gz" then
of_string_opt (Filename.chop_suffix base "+opam.tar.gz")
else
match parent with
| "files" ->
let parent2 = Filename.basename (Filename.dirname (Filename.dirname f)) in
of_string_opt parent2
| _ -> None
end
let base = Filename.basename f in
let parent = Filename.basename (Filename.dirname f) in
match base with
| "opam" | "descr" | "url" ->
of_string_opt parent
| _ ->
if Filename.check_suffix base ".opam" then
of_string_opt (Filename.chop_suffix base ".opam")
else if Filename.check_suffix base "+opam.tar.gz" then
of_string_opt (Filename.chop_suffix base "+opam.tar.gz")
else
match parent with
| "files" ->
let parent2 = Filename.basename (Filename.dirname (Filename.dirname f)) in
of_string_opt parent2
| _ -> None

let of_dirname d =
of_string_opt (OpamFilename.Base.to_string (OpamFilename.basename_dir d))
Expand Down
2 changes: 1 addition & 1 deletion src/opamProcess.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let create ?info ?stdout ?stderr ?env ~verbose cmd args =
let fd = Unix.openfile f open_flags 0o644 in
let close_fd () = Unix.close fd in
if verbose then (
let chan = Unix.open_process_out ("tee " ^ f) in
let chan = Unix.open_process_out ("tee " ^ Filename.quote f) in
let close () =
match Unix.close_process_out chan with
| _ -> close_fd () in
Expand Down

0 comments on commit 54eff3f

Please sign in to comment.