Node: allow identity.json to stay when clearing the data-dir
This commit is contained in:
parent
e91f5bc588
commit
97d983285e
@ -13,6 +13,8 @@ type t = string
|
|||||||
|
|
||||||
let data_version = "0.0.1"
|
let data_version = "0.0.1"
|
||||||
|
|
||||||
|
let default_identity_file_name = "identity.json"
|
||||||
|
|
||||||
let version_encoding = Data_encoding.(obj1 (req "version" string))
|
let version_encoding = Data_encoding.(obj1 (req "version" string))
|
||||||
|
|
||||||
let version_file_name = "version.json"
|
let version_file_name = "version.json"
|
||||||
@ -83,12 +85,15 @@ let check_data_dir_version data_dir =
|
|||||||
return ()
|
return ()
|
||||||
|
|
||||||
let ensure_data_dir data_dir =
|
let ensure_data_dir data_dir =
|
||||||
if Sys.file_exists data_dir &&
|
let write_version () =
|
||||||
(Array.length (Sys.readdir data_dir)) > 0
|
|
||||||
then
|
|
||||||
check_data_dir_version data_dir
|
|
||||||
else
|
|
||||||
Lwt_utils.create_dir ~perm:0o700 data_dir >>= fun () ->
|
|
||||||
Data_encoding_ezjsonm.write_file
|
Data_encoding_ezjsonm.write_file
|
||||||
(version_file data_dir)
|
(version_file data_dir)
|
||||||
(Data_encoding.Json.construct version_encoding data_version)
|
(Data_encoding.Json.construct version_encoding data_version) in
|
||||||
|
if Sys.file_exists data_dir then
|
||||||
|
match Sys.readdir data_dir with
|
||||||
|
| [||] -> write_version ()
|
||||||
|
| [| single |] when single = default_identity_file_name -> write_version ()
|
||||||
|
| _ -> check_data_dir_version data_dir
|
||||||
|
else
|
||||||
|
Lwt_utils.create_dir ~perm:0o700 data_dir >>= fun () ->
|
||||||
|
write_version ()
|
||||||
|
@ -13,6 +13,7 @@ type error += Invalid_data_dir_version of t * t
|
|||||||
type error += Could_not_read_data_dir_version of string
|
type error += Could_not_read_data_dir_version of string
|
||||||
|
|
||||||
val data_version : t
|
val data_version : t
|
||||||
|
val default_identity_file_name : string
|
||||||
|
|
||||||
val pp : Format.formatter -> t -> unit
|
val pp : Format.formatter -> t -> unit
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ let (//) = Filename.concat
|
|||||||
|
|
||||||
(** Commands *)
|
(** Commands *)
|
||||||
|
|
||||||
let identity_file data_dir = data_dir // Node_identity_file.default_name
|
let identity_file data_dir = data_dir // Node_data_version.default_identity_file_name
|
||||||
|
|
||||||
let show { Node_config_file.data_dir } =
|
let show { Node_config_file.data_dir } =
|
||||||
Node_identity_file.read (identity_file data_dir) >>=? fun id ->
|
Node_identity_file.read (identity_file data_dir) >>=? fun id ->
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
let default_name = "identity.json"
|
|
||||||
|
|
||||||
type error += No_identity_file of string
|
type error += No_identity_file of string
|
||||||
type error += Insufficient_proof_of_work of { expected: float }
|
type error += Insufficient_proof_of_work of { expected: float }
|
||||||
|
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(**************************************************************************)
|
(**************************************************************************)
|
||||||
|
|
||||||
val default_name: string
|
|
||||||
|
|
||||||
type error += No_identity_file of string
|
type error += No_identity_file of string
|
||||||
type error += Insufficient_proof_of_work of { expected: float }
|
type error += Insufficient_proof_of_work of { expected: float }
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ let init_node ?sandbox (config : Node_config_file.t) =
|
|||||||
config.net.bootstrap_peers) >>= fun trusted_points ->
|
config.net.bootstrap_peers) >>= fun trusted_points ->
|
||||||
Node_identity_file.read
|
Node_identity_file.read
|
||||||
(config.data_dir //
|
(config.data_dir //
|
||||||
Node_identity_file.default_name) >>=? fun identity ->
|
Node_data_version.default_identity_file_name) >>=? fun identity ->
|
||||||
lwt_log_notice
|
lwt_log_notice
|
||||||
"Peer's global id: %a"
|
"Peer's global id: %a"
|
||||||
P2p.Peer_id.pp identity.peer_id >>= fun () ->
|
P2p.Peer_id.pp identity.peer_id >>= fun () ->
|
||||||
|
Loading…
Reference in New Issue
Block a user