Skip to content

Commit

Permalink
[fix] Sys.is_directory can throw
Browse files Browse the repository at this point in the history
  • Loading branch information
Hongbo Zhang committed May 10, 2016
1 parent 1393370 commit 276d3d3
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 8 deletions.
2 changes: 2 additions & 0 deletions jscomp/compiler.mllib
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ ext_array
ext_bytes
ext_map
ext_hashtbl
ext_sys


lam_mk
lam_comb
Expand Down
4 changes: 2 additions & 2 deletions jscomp/ext_filename.ml
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ let node_relative_path (file1 : t)
*)
let resolve ~cwd module_name =
let rec aux origin cwd module_name =
let v = ( cwd // node_modules) // module_name
let v = cwd // node_modules // module_name
in
if Sys.is_directory v then v
if Ext_sys.is_directory_no_exn v then v
else
let cwd' = Filename.dirname cwd in
if String.length cwd' < String.length cwd then
Expand Down
27 changes: 27 additions & 0 deletions jscomp/ext_sys.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a later version).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)


let is_directory_no_exn f =
try Sys.is_directory f with _ -> false
25 changes: 25 additions & 0 deletions jscomp/ext_sys.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a later version).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

val is_directory_no_exn : string -> bool
13 changes: 9 additions & 4 deletions jscomp/test/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ basic_module_test.cmi :
const_block_test.cmi :
demo_int_map.cmi :
ext_pervasives.cmi : ../stdlib/int32.cmi ../stdlib/format.cmi
ext_sys.cmi :
float_record.cmi :
inline_edge_cases.cmi :
inline_map_test.cmi :
Expand Down Expand Up @@ -148,10 +149,10 @@ ext_array.cmx : ../stdlib/list.cmx ../stdlib/array.cmx
ext_bytes.cmj : ../stdlib/bytes.cmi
ext_bytes.cmx : ../stdlib/bytes.cmx
ext_filename.cmj : ../stdlib/sys.cmi ../stdlib/string.cmi ../stdlib/list.cmi \
../stdlib/lazy.cmi ../stdlib/filename.cmi ext_string.cmj \
../stdlib/lazy.cmi ../stdlib/filename.cmi ext_sys.cmi ext_string.cmj \
ext_pervasives.cmi
ext_filename.cmx : ../stdlib/sys.cmx ../stdlib/string.cmx ../stdlib/list.cmx \
../stdlib/lazy.cmx ../stdlib/filename.cmx ext_string.cmx \
../stdlib/lazy.cmx ../stdlib/filename.cmx ext_sys.cmx ext_string.cmx \
ext_pervasives.cmx
ext_list.cmj : ../stdlib/list.cmi ../stdlib/array.cmi
ext_list.cmx : ../stdlib/list.cmx ../stdlib/array.cmx
Expand All @@ -165,6 +166,8 @@ ext_string.cmj : ../stdlib/string.cmi ext_bytes.cmj ../stdlib/char.cmi \
../stdlib/bytes.cmi
ext_string.cmx : ../stdlib/string.cmx ext_bytes.cmx ../stdlib/char.cmx \
../stdlib/bytes.cmx
ext_sys.cmj : ../stdlib/sys.cmi ext_sys.cmi
ext_sys.cmx : ../stdlib/sys.cmx ext_sys.cmi
extensible_variant_test.cmj : mt.cmi
extensible_variant_test.cmx : mt.cmx
fail_comp.cmj :
Expand Down Expand Up @@ -762,10 +765,10 @@ ext_array.cmj : ../stdlib/list.cmj ../stdlib/array.cmj
ext_bytes.cmo : ../stdlib/bytes.cmi
ext_bytes.cmj : ../stdlib/bytes.cmj
ext_filename.cmo : ../stdlib/sys.cmi ../stdlib/string.cmi ../stdlib/list.cmi \
../stdlib/lazy.cmi ../stdlib/filename.cmi ext_string.cmo \
../stdlib/lazy.cmi ../stdlib/filename.cmi ext_sys.cmi ext_string.cmo \
ext_pervasives.cmi
ext_filename.cmj : ../stdlib/sys.cmj ../stdlib/string.cmj ../stdlib/list.cmj \
../stdlib/lazy.cmj ../stdlib/filename.cmj ext_string.cmj \
../stdlib/lazy.cmj ../stdlib/filename.cmj ext_sys.cmj ext_string.cmj \
ext_pervasives.cmj
ext_list.cmo : ../stdlib/list.cmi ../stdlib/array.cmi
ext_list.cmj : ../stdlib/list.cmj ../stdlib/array.cmj
Expand All @@ -779,6 +782,8 @@ ext_string.cmo : ../stdlib/string.cmi ext_bytes.cmo ../stdlib/char.cmi \
../stdlib/bytes.cmi
ext_string.cmj : ../stdlib/string.cmj ext_bytes.cmj ../stdlib/char.cmj \
../stdlib/bytes.cmj
ext_sys.cmo : ../stdlib/sys.cmi ext_sys.cmi
ext_sys.cmj : ../stdlib/sys.cmj ext_sys.cmi
extensible_variant_test.cmo : mt.cmi
extensible_variant_test.cmj : mt.cmj
fail_comp.cmo :
Expand Down
1 change: 1 addition & 0 deletions jscomp/test/ext_sys.ml
1 change: 1 addition & 0 deletions jscomp/test/ext_sys.mli
4 changes: 3 additions & 1 deletion jscomp/test/test.mllib
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,6 @@ ext_pervasives

test_const_propogate

limits_test
limits_test

ext_sys
3 changes: 2 additions & 1 deletion lib/js/test/ext_filename.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var Pervasives = require("../pervasives");
var Block = require("../block");
var Ext_string = require("./ext_string");
var Curry = require("../curry");
var Ext_sys = require("./ext_sys");
var Ext_pervasives = require("./ext_pervasives");
var $$String = require("../string");
var Format = require("../format");
Expand Down Expand Up @@ -250,7 +251,7 @@ function resolve(cwd, module_name) {
while(true) {
var cwd$1 = _cwd;
var v = Filename.concat(Filename.concat(cwd$1, node_modules), module_name$1);
if (Caml_sys.caml_sys_is_directory(v)) {
if (Ext_sys.is_directory_no_exn(v)) {
return v;
}
else {
Expand Down
16 changes: 16 additions & 0 deletions lib/js/test/ext_sys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.3 , PLEASE EDIT WITH CARE
'use strict';

var Caml_sys = require("../caml_sys");

function is_directory_no_exn(f) {
try {
return Caml_sys.caml_sys_is_directory(f);
}
catch (exn){
return /* false */0;
}
}

exports.is_directory_no_exn = is_directory_no_exn;
/* No side effect */

0 comments on commit 276d3d3

Please sign in to comment.