From 9d5d18cea791efa7b948c8a76111b113a4689b10 Mon Sep 17 00:00:00 2001 From: Thomas Gazagnaire Date: Wed, 17 May 2017 15:30:29 -0700 Subject: [PATCH] client: remove "rename" API calls Signed-off-by: Thomas Gazagnaire --- api/ocaml/9p/datakit_client_9p.ml | 23 +++--------- api/ocaml/datakit_client.ml | 2 -- api/ocaml/datakit_client.mli | 9 ----- tests/common/test_client.ml | 59 ------------------------------- 4 files changed, 5 insertions(+), 88 deletions(-) diff --git a/api/ocaml/9p/datakit_client_9p.ml b/api/ocaml/9p/datakit_client_9p.ml index ceafe036f..8673c94c4 100644 --- a/api/ocaml/9p/datakit_client_9p.ml +++ b/api/ocaml/9p/datakit_client_9p.ml @@ -178,11 +178,13 @@ module Make(P9p : Protocol_9p.Client.S) = struct let with_file_full t path fn = P9p.with_fid t.conn (fun newfid -> - P9p.walk_from_root t.conn newfid path >|= wrap_9p >>*= fn newfid >|= fun x -> Ok x + P9p.walk_from_root t.conn newfid path >|= wrap_9p >>*= + fn newfid >|= fun x -> Ok x ) >|= function - | Error _ as e -> wrap_9p e (* Error from [with_fid] itself or [walk_from_root]. *) - | Ok x -> x (* Error or success from [fn] *) + | Ok x -> x (* Error or success from [fn] *) + | Error _ as e -> wrap_9p e (* Error from [with_fid] itself + or [walk_from_root]. *) let with_file t path fn = with_file_full t path (fun fid _resp -> fn fid) @@ -272,13 +274,6 @@ module Make(P9p : Protocol_9p.Client.S) = struct Log.debug (fun f -> f "remove %a" pp_path path); P9p.remove t.conn path >|= wrap_9p - let rename t path new_name = - Log.debug (fun f -> f "rename %a to %s" pp_path path new_name); - with_file t path (fun fid -> - P9p.LowLevel.update t.conn ~name:new_name fid - >|= wrap_9p - ) - let truncate t path new_length = Log.debug (fun f -> f "truncate %a to %Ld" pp_path path new_length); with_file t path (fun fid -> @@ -599,9 +594,6 @@ module Make(P9p : Protocol_9p.Client.S) = struct let remove t path = FS.remove t.fs (rw_path t path) - let rename t path new_name = - FS.rename t.fs (rw_path t path) new_name - let truncate t path new_length = FS.truncate t.fs (rw_path t path) new_length @@ -703,11 +695,6 @@ module Make(P9p : Protocol_9p.Client.S) = struct let remove t = FS.remove t.fs (branch_dir t) - let rename t new_name = - FS.rename t.fs (branch_dir t) new_name >>*= fun () -> - t.name <- new_name; - ok () - let node_of_hash t = function | "" -> ok None | line -> diff --git a/api/ocaml/datakit_client.ml b/api/ocaml/datakit_client.ml index b6eeee918..87c397543 100644 --- a/api/ocaml/datakit_client.ml +++ b/api/ocaml/datakit_client.ml @@ -140,7 +140,6 @@ module type S = sig val create_or_replace_file: t -> Path.t -> Cstruct.t -> unit result val set_executable: t -> Path.t -> bool -> unit result val remove: t -> Path.t -> unit result - val rename: t -> Path.t -> string -> unit result val truncate: t -> Path.t -> int64 -> unit result val make_dirs: t -> Path.t -> unit result val commit: t -> message:string -> unit result @@ -162,7 +161,6 @@ module type S = sig type t val name: t -> string val remove: t -> unit result - val rename: t -> string -> unit result val head: t -> Commit.t option result val wait_for_head: t -> ?switch:Lwt_switch.t -> (Commit.t option -> [`Finish of 'a | `Again | `Abort] result) -> diff --git a/api/ocaml/datakit_client.mli b/api/ocaml/datakit_client.mli index 16c424541..bc76f3bb1 100644 --- a/api/ocaml/datakit_client.mli +++ b/api/ocaml/datakit_client.mli @@ -213,11 +213,6 @@ module type S = sig (** [remove t path] removes [path]. If [path] is a directory then the entire subtree is removed. *) - val rename: t -> Path.t -> string -> unit result - (** [rename t path new_name] changes the basename of [path] to - [new_name]. Note: it is only possible to rename within a - directory (this is a 9p limitation). *) - val truncate: t -> Path.t -> int64 -> unit result (** [truncate t path length] sets the length of the file at [path] to [length]. If [length] is longer than the current length, @@ -301,10 +296,6 @@ module type S = sig (** [remove t] deletes branch [t]. If [t] does not exist, this does nothing. *) - val rename: t -> string -> unit result - (** [rename t new_name] changes the name of this branch. It is an - error if [new_name] already exists. *) - val head: t -> Commit.t option result (** [head t] is the current head of the branch, or [None] if it doesn't currently exist. *) diff --git a/tests/common/test_client.ml b/tests/common/test_client.ml index b6b05a8e7..b7a4a5495 100644 --- a/tests/common/test_client.ml +++ b/tests/common/test_client.ml @@ -635,62 +635,6 @@ module Make (DK: S) = struct expect_file_event "Makefile" makefile_events None >>= fun () -> Lwt.return_unit - let test_rename_branch dk = - DK.branch dk "old" >>*= fun branch -> - create_in_trans branch (p "") "key" (v "value") >>*= fun () -> - DK.Branch.rename branch "new" >>*= fun () -> - DK.branches dk >>*= fun branches -> - Alcotest.(check (list string)) "New branches" ["new"] branches; - DK.branch dk "new" >>*= fun new_branch -> - expect_head new_branch >>*= fun head -> - DK.Commit.tree head >>*= fun tree -> - DK.Tree.read_file tree (p "key") |> check_file "Moved" "value" >>= fun () -> - DK.Branch.remove branch >>*= fun () -> - DK.branches dk >>*= fun branches -> - Alcotest.(check (list string)) "New gone" [] branches; - Lwt.return_unit - - let test_rename_dir dk = - DK.branch dk "master" >>*= fun master -> - DK.Branch.with_transaction master (fun t -> - DK.Transaction.create_dir t (p "old") >>*= fun () -> - DK.Transaction.rename t (p "old") "new" >>*= fun () -> - DK.Transaction.read_dir t (p "") >>*= fun items -> - Alcotest.(check (list string)) "New files" ["new"] items; - DK.Transaction.abort t - ) >|*= fun () -> () - - let test_rename_file dk = - DK.branch dk "master" >>*= fun master -> - DK.Branch.with_transaction master (fun t -> - DK.Transaction.create_file t (p "old") (v "data") >>*= fun () -> - DK.Transaction.rename t (p "old") "new" >>*= fun () -> - DK.Transaction.read_dir t (p "") >>*= fun items -> - Alcotest.(check (list string)) "New files" ["new"] items; - (* Check rename detects errors - Note: we currently allow overwriting an empty directory *) - DK.Transaction.create_dir t (p "dir") >>*= fun () -> - DK.Transaction.create_file t (p "dir/precious") (v "data") - >>*= fun () -> - DK.Transaction.rename t (p "new") "dir" >>= function - | Ok () -> Alcotest.fail "Shouldn't be able to rename over a directory" - | Error `Is_dir -> begin - (* Rename when source has been deleted. Ideally, we should also - check it hasn't been replaced by something with the same - name. *) - DK.Transaction.remove t (p "new") >>*= fun () -> - DK.Transaction.rename t (p "new") "reborn" >>= function - | Ok () -> Alcotest.fail "Shouldn't be able to rename a missing source" - | Error `Does_not_exist -> DK.Transaction.commit t ~message:"rename" - | Error e -> Alcotest.fail (Fmt.to_to_string DK.pp_error e) - end - | Error e -> Alcotest.fail (Fmt.to_to_string DK.pp_error e) - ) >>*= fun () -> - expect_head master >>*= fun head -> - DK.Commit.tree head >>*= fun tree -> - DK.Tree.read_dir tree (p "") >|*= fun items -> - Alcotest.(check (list string)) "New files" ["dir"] items - let test_truncate dk = DK.branch dk "master" >>*= fun master -> DK.Branch.with_transaction master (fun t -> @@ -779,9 +723,6 @@ module Make (DK: S) = struct "Transaction" , `Quick, run test_transaction; "Watch" , `Quick, run test_watch; "Make dirs" , `Quick, run test_make_dirs; - "Rename branch" , `Quick, run test_rename_branch; - "Rename dir" , `Quick, run test_rename_dir; - "Rename file" , `Quick, run test_rename_file; "Truncate" , `Quick, run test_truncate; "Parents" , `Quick, run test_parents; "Merge" , `Quick, run test_merge;