Client/Context_unix: code style

This commit is contained in:
MBourgoin 2018-11-06 13:10:24 +01:00 committed by Grégoire Henry
parent 24355f0ae9
commit e35e263fd6
No known key found for this signature in database
GPG Key ID: 50D984F20BD445D2

View File

@ -32,27 +32,25 @@ class unix_wallet ~base_dir : wallet = object (self)
base_dir
(Str.(global_replace (regexp_string " ") "_" alias_name) ^ "s")
method with_lock : type a. ( unit -> a Lwt.t) -> a Lwt.t =
method with_lock : type a. (unit -> a Lwt.t) -> a Lwt.t =
(fun f ->
let unlock fd =
let fd = Lwt_unix.unix_file_descr fd in
Unix.lockf fd Unix.F_ULOCK 0;
Unix.close fd
in
Unix.lockf fd Unix.F_ULOCK 0 ;
Unix.close fd in
let lock () =
Lwt_unix.openfile (Filename.concat base_dir "wallet_lock")
Lwt_unix.[O_CREAT; O_WRONLY] 0o644 >>= fun fd ->
Lwt_unix.[ O_CREAT ; O_WRONLY ] 0o644 >>= fun fd ->
Lwt_unix.lockf fd Unix.F_LOCK 0 >>= fun () ->
Lwt.return (fd,(Lwt_unix.on_signal Sys.sigint
(fun _s ->
unlock fd;
exit 0 (* exit code? *) )))
in
lock () >>= fun (fd,sh) ->
Lwt.return (fd, (Lwt_unix.on_signal Sys.sigint
(fun _s ->
unlock fd ;
exit 0 (* exit code? *) ))) in
lock () >>= fun (fd, sh) ->
(* catch might be useless if f always uses the error monad *)
Lwt.catch f (function e -> Lwt.return (unlock fd; raise e)) >>= fun res ->
Lwt.catch f (function e -> Lwt.return (unlock fd ; raise e)) >>= fun res ->
Lwt.return (unlock fd) >>= fun () ->
Lwt_unix.disable_signal_handler sh;
Lwt_unix.disable_signal_handler sh ;
Lwt.return res)
method load : type a. string -> default:a -> a Data_encoding.encoding -> a tzresult Lwt.t =