Skip to content

Commit

Permalink
Merge pull request #563 from samoht/rename
Browse files Browse the repository at this point in the history
client: remove "rename" API calls
  • Loading branch information
samoht authored May 18, 2017
2 parents 3617306 + 9d5d18c commit 160f900
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 88 deletions.
23 changes: 5 additions & 18 deletions api/ocaml/9p/datakit_client_9p.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 ->
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 ->
Expand Down
2 changes: 0 additions & 2 deletions api/ocaml/datakit_client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) ->
Expand Down
9 changes: 0 additions & 9 deletions api/ocaml/datakit_client.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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. *)
Expand Down
59 changes: 0 additions & 59 deletions tests/common/test_client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 160f900

Please sign in to comment.