diff --git a/opam-ci-check/bin/main.ml b/opam-ci-check/bin/main.ml index 09f63de5..ad67c361 100644 --- a/opam-ci-check/bin/main.ml +++ b/opam-ci-check/bin/main.ml @@ -68,15 +68,16 @@ let lint package_specs local_repo_dir = | Some opam_repo_dir -> ( print_endline @@ Printf.sprintf "Linting opam-repository at %s ..." opam_repo_dir; - Dir_helpers.with_temp_dir "opam-ci-check-lint-" @@ fun dir -> + OpamFilename.with_tmp_dir @@ fun dir -> let process_package { pkg; src; newly_published } = let opam = read_package_opam ~opam_repo_dir pkg in let pkg_src_dir = if Option.is_none src then - let dir = dir // OpamPackage.to_string pkg in + let dir = + OpamFilename.Dir.to_string dir // OpamPackage.to_string pkg + in fetch_package_src ~dir ~pkg opam - else - src + else src in Lint.v ~pkg ~newly_published ~pkg_src_dir opam in diff --git a/opam-ci-check/lib/dir_helpers.ml b/opam-ci-check/lib/dir_helpers.ml deleted file mode 100644 index b63b867c..00000000 --- a/opam-ci-check/lib/dir_helpers.ml +++ /dev/null @@ -1,42 +0,0 @@ -(* SPDX-License-Identifier: Apache-2.0 - * Copyright (c) 2024 Puneeth Chaganti , Shon Feder , Tarides - *) - -(*Generate random temporary file names. **) -let temp_file_name dir prefix suffix = - let prng = Random.State.make_self_init () in - let random_suffix = string_of_int (Random.State.int prng 0x10000000) in - Filename.concat dir (prefix ^ random_suffix ^ suffix) - -(*Create a temporary directory with the given prefix. **) -let create_temp_dir prefix = - let base_temp_dir = Filename.get_temp_dir_name () in - let unique_temp_dir = temp_file_name base_temp_dir prefix "" in - Unix.mkdir unique_temp_dir 0o700; - unique_temp_dir - -let remove_dir dir = - let rec remove_dir_rec dir = - let entries = Sys.readdir dir in - Array.iter - (fun entry -> - let entry = Filename.concat dir entry in - let entry_is_directory = - (* Sys.is_directory raises a Sys_error for broken symlinks *) - try Sys.is_directory entry with Sys_error _ -> false - in - if entry_is_directory then remove_dir_rec entry else Sys.remove entry) - entries; - Sys.rmdir dir - in - remove_dir_rec dir - -let with_temp_dir prefix f = - let dir = create_temp_dir prefix in - match f dir with - | exception exn -> - remove_dir dir; - raise exn - | result -> - remove_dir dir; - result diff --git a/opam-ci-check/lib/lint.ml b/opam-ci-check/lib/lint.ml index f69ee61b..44dcc535 100644 --- a/opam-ci-check/lib/lint.ml +++ b/opam-ci-check/lib/lint.ml @@ -2,7 +2,6 @@ * Copyright (c) 2024 Puneeth Chaganti , Shon Feder , Tarides *) -module D = Dir_helpers module O = Opam_helpers let ( // ) = Filename.concat diff --git a/opam-ci-check/lib/opam_ci_check.ml b/opam-ci-check/lib/opam_ci_check.ml index ab1c6b18..d0b65550 100644 --- a/opam-ci-check/lib/opam_ci_check.ml +++ b/opam-ci-check/lib/opam_ci_check.ml @@ -10,5 +10,4 @@ module Variant = Variant module Opam_version = Opam_version module Compiler_version = Compiler_version module Spec = Spec -module Dir_helpers = Dir_helpers module Opam_helpers = Opam_helpers diff --git a/opam-ci-check/lib/test.ml b/opam-ci-check/lib/test.ml index 1cffb2cd..fe525bb8 100644 --- a/opam-ci-check/lib/test.ml +++ b/opam-ci-check/lib/test.ml @@ -3,7 +3,6 @@ *) module H = Dune_helpers -module D = Dir_helpers type error = OpamPackage.t * exn @@ -59,7 +58,7 @@ let test_packages_with_dune opam_repository target_pkg packages = OpamConsole.msg "Installing latest version of reverse dependencies with pinned %s\n" (OpamPackage.to_string target); - let parent = D.create_temp_dir "revdeps_" in + let parent = OpamFilename.mk_tmp_dir () |> OpamFilename.Dir.to_string in (* FIXME: there can be 1000s of revdeps?! *) let selected_packages = H.take 3 packages in (* Prompt before creating the projects *)