diff --git a/src/node/main/node_data_version.ml b/src/node/main/node_data_version.ml index f0fa265cb..b3db44e12 100644 --- a/src/node/main/node_data_version.ml +++ b/src/node/main/node_data_version.ml @@ -13,6 +13,8 @@ type t = string let data_version = "0.0.1" +let default_identity_file_name = "identity.json" + let version_encoding = Data_encoding.(obj1 (req "version" string)) let version_file_name = "version.json" @@ -83,12 +85,15 @@ let check_data_dir_version data_dir = return () let ensure_data_dir data_dir = - if Sys.file_exists data_dir && - (Array.length (Sys.readdir data_dir)) > 0 - then - check_data_dir_version data_dir - else - Lwt_utils.create_dir ~perm:0o700 data_dir >>= fun () -> + let write_version () = Data_encoding_ezjsonm.write_file (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 () diff --git a/src/node/main/node_data_version.mli b/src/node/main/node_data_version.mli index db3a796da..d090571a0 100644 --- a/src/node/main/node_data_version.mli +++ b/src/node/main/node_data_version.mli @@ -13,6 +13,7 @@ type error += Invalid_data_dir_version of t * t type error += Could_not_read_data_dir_version of string val data_version : t +val default_identity_file_name : string val pp : Format.formatter -> t -> unit diff --git a/src/node/main/node_identity_command.ml b/src/node/main/node_identity_command.ml index d3635ceb1..b5f0ffbe9 100644 --- a/src/node/main/node_identity_command.ml +++ b/src/node/main/node_identity_command.ml @@ -11,7 +11,7 @@ let (//) = Filename.concat (** 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 } = Node_identity_file.read (identity_file data_dir) >>=? fun id -> diff --git a/src/node/main/node_identity_file.ml b/src/node/main/node_identity_file.ml index 50e9661a3..1294bd460 100644 --- a/src/node/main/node_identity_file.ml +++ b/src/node/main/node_identity_file.ml @@ -7,8 +7,6 @@ (* *) (**************************************************************************) -let default_name = "identity.json" - type error += No_identity_file of string type error += Insufficient_proof_of_work of { expected: float } diff --git a/src/node/main/node_identity_file.mli b/src/node/main/node_identity_file.mli index 167333da5..7b770af08 100644 --- a/src/node/main/node_identity_file.mli +++ b/src/node/main/node_identity_file.mli @@ -7,8 +7,6 @@ (* *) (**************************************************************************) -val default_name: string - type error += No_identity_file of string type error += Insufficient_proof_of_work of { expected: float } diff --git a/src/node/main/node_run_command.ml b/src/node/main/node_run_command.ml index e688e78f7..bae311d07 100644 --- a/src/node/main/node_run_command.ml +++ b/src/node/main/node_run_command.ml @@ -117,7 +117,7 @@ let init_node ?sandbox (config : Node_config_file.t) = config.net.bootstrap_peers) >>= fun trusted_points -> Node_identity_file.read (config.data_dir // - Node_identity_file.default_name) >>=? fun identity -> + Node_data_version.default_identity_file_name) >>=? fun identity -> lwt_log_notice "Peer's global id: %a" P2p.Peer_id.pp identity.peer_id >>= fun () ->