Skip to content

Commit

Permalink
Cosmetic changes only
Browse files Browse the repository at this point in the history
  • Loading branch information
David Scott committed Aug 5, 2012
1 parent 95fffcd commit f823014
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 36 deletions.
39 changes: 18 additions & 21 deletions server/store.ml
Expand Up @@ -249,23 +249,6 @@ let rec lookup_modify node path fct =
let apply_modify rnode path fct =
lookup_modify rnode path fct

let rec lookup_get node path =
match path with
| [] -> raise (Invalid_path)
| h :: [] ->
(try
Node.find node h
with Not_found ->
raise Doesnt_exist)
| h :: l -> let cnode = Node.find node h in lookup_get cnode l

let get_node rnode path =
if path = [] then
Some rnode
else (
try Some (lookup_get rnode path) with Doesnt_exist -> None
)

(* get the deepest existing node for this path *)
let rec get_deepest_existing_node node path =
let rec f node = function
Expand Down Expand Up @@ -378,8 +361,22 @@ let path_setperms store perm path perms =
Path.apply_modify store.root path do_setperms

(* accessing functions *)
let get_node store path =
Path.get_node store.root path
let lookup node path =
let rec lookup_get node path =
match path with
| [] -> raise (Invalid_path)
| h :: [] ->
(try
Node.find node h
with Not_found ->
raise Path.Doesnt_exist)
| h :: l -> let cnode = Node.find node h in lookup_get cnode l in

if path = [] then
Some node
else (
try Some (lookup_get node path) with Path.Doesnt_exist -> None
)

let get_deepest_existing_node store path =
Path.get_deepest_existing_node store.root path
Expand Down Expand Up @@ -484,15 +481,15 @@ let mkdir store perm path =
Quota.add_entry store.quota owner

let rm store perm path =
let rmed_node = Path.get_node store.root path in
let rmed_node = lookup store.root path in
match rmed_node with
| None -> raise Path.Doesnt_exist
| Some rmed_node ->
store.root <- path_rm store perm path;
Node.recurse (fun node -> Quota.del_entry store.quota (Node.get_owner node)) rmed_node

let setperms store perm path nperms =
match Path.get_node store.root path with
match lookup store.root path with
| None -> raise Path.Doesnt_exist
| Some node ->
let old_owner = Node.get_owner node in
Expand Down
28 changes: 19 additions & 9 deletions server/store.mli
Expand Up @@ -73,22 +73,32 @@ module Path : sig
(** [create path default] is the absolute path of [path], where if [path]
is relative then it is resolved relative to [default] *)

val to_name: t -> Name.t
val to_name: t -> Name.t
(** [to_name t] returns the associated Name.t, suitable for watching *)

val to_string: t -> string

val get_hierarchy: t -> t list
val to_string: t -> string
(** [to_string t] returns [t] as a '/'-separated path string *)

val get_node: Node.t -> t -> Node.t option
val get_hierarchy: t -> t list
(** [get_hierarchy t] returns all t's on the path from the root node to [t] *)

val get_common_prefix: t -> t -> t
val get_common_prefix: t -> t -> t
(** [get_common_prefix a b] returns the largest common prefix of [a] and [b] *)

val get_parent: t -> t
val get_parent: t -> t
(** [get_parent t] returns the parent node of [t]. The parent of the root node
is itself. *)

val make_relative: t -> Name.t -> Name.t
val make_relative: t -> Name.t -> Name.t
(** [make_relative base name] returns a Name.t which is [name] transformed into
a relative path from [base] *)

end

val lookup: Node.t -> Path.t -> Node.t option
(** [lookup node path] follows [path] from [node] and returns the node it
finds, or None *)

type t =
{
mutable stat_transaction_coalesce: int;
Expand Down Expand Up @@ -120,7 +130,7 @@ val read: t -> Perms.t -> Path.t -> string

val getperms: t -> Perms.t -> Path.t -> Xs_packet.ACL.t

val get_node: t -> Path.t -> Node.t option

val set_node: t -> Path.t -> Node.t -> unit

val mark_symbols: t -> unit
12 changes: 6 additions & 6 deletions server/transaction.ml
Expand Up @@ -26,8 +26,8 @@ let do_coalesce = ref true
let check_parents_perms_identical root1 root2 path =
let hierarch = Store.Path.get_hierarchy path in
let permdiff = List.fold_left (fun acc path ->
let n1 = Store.Path.get_node root1 path
and n2 = Store.Path.get_node root2 path in
let n1 = Store.lookup root1 path
and n2 = Store.lookup root2 path in
match n1, n2 with
| Some n1, Some n2 ->
(Store.Node.get_perms n1) <> (Store.Node.get_perms n2) || acc
Expand All @@ -45,8 +45,8 @@ let test_coalesce oldroot currentroot optpath =
match optpath with
| None -> true
| Some path ->
let oldnode = Store.Path.get_node oldroot path
and currentnode = Store.Path.get_node currentroot path in
let oldnode = Store.lookup oldroot path
and currentnode = Store.lookup currentroot path in

match oldnode, currentnode with
| (Some oldnode), (Some currentnode) ->
Expand All @@ -58,7 +58,7 @@ let test_coalesce oldroot currentroot optpath =
| None, None -> (
(* ok then it doesn't exists in the old version and the current version,
just sneak it in as a child of the parent node if it exists, or else fail *)
let pnode = Store.Path.get_node currentroot (Store.Path.get_parent path) in
let pnode = Store.lookup currentroot (Store.Path.get_parent path) in
match pnode with
| None -> false (* ok it doesn't exists, just bail out. *)
| Some pnode -> true
Expand Down Expand Up @@ -170,7 +170,7 @@ let commit ~con t =
if can_coalesce oldroot cstore.Store.root t.read_lowpath
&& can_coalesce oldroot cstore.Store.root t.write_lowpath then (
maybe (fun p ->
let n = Store.get_node store p in
let n = Store.lookup store.Store.root p in

(* it has to be in the store, otherwise it means bugs
in the lowpath registration. we don't need to handle none. *)
Expand Down

0 comments on commit f823014

Please sign in to comment.