From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id E01016217D
 for <pbs-devel@lists.proxmox.com>; Mon, 21 Feb 2022 11:39:52 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id D392171B3
 for <pbs-devel@lists.proxmox.com>; Mon, 21 Feb 2022 11:39:22 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id B497F7196
 for <pbs-devel@lists.proxmox.com>; Mon, 21 Feb 2022 11:39:20 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 8CE3F46173
 for <pbs-devel@lists.proxmox.com>; Mon, 21 Feb 2022 11:39:20 +0100 (CET)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Mon, 21 Feb 2022 11:39:15 +0100
Message-Id: <20220221103918.2407442-2-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20220221103918.2407442-1-d.csapak@proxmox.com>
References: <20220221103918.2407442-1-d.csapak@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.156 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 T_SCC_BODY_TEXT_LINE    -0.01 -
Subject: [pbs-devel] [PATCH proxmox v2 1/2] move io error helpers to
 proxmox-lang
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Mon, 21 Feb 2022 10:39:52 -0000

this removes proxmox_sys as a dependecy for proxmox-async

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 proxmox-async/Cargo.toml                     |  2 +-
 proxmox-async/src/compression.rs             |  2 +-
 proxmox-async/src/io/async_channel_writer.rs |  3 +-
 proxmox-http/Cargo.toml                      |  2 +
 proxmox-http/src/websocket/mod.rs            |  2 +-
 proxmox-lang/src/error.rs                    | 53 ++++++++++++++++++++
 proxmox-lang/src/lib.rs                      |  1 +
 proxmox-sys/src/error.rs                     |  7 +--
 proxmox-sys/src/linux/pid.rs                 |  4 +-
 proxmox-sys/src/macros.rs                    | 44 ----------------
 proxmox-sys/src/mmap.rs                      |  4 +-
 11 files changed, 66 insertions(+), 58 deletions(-)
 create mode 100644 proxmox-lang/src/error.rs

diff --git a/proxmox-async/Cargo.toml b/proxmox-async/Cargo.toml
index 291ff32..917e5f5 100644
--- a/proxmox-async/Cargo.toml
+++ b/proxmox-async/Cargo.toml
@@ -20,9 +20,9 @@ pin-utils = "0.1.0"
 tokio = { version = "1.0", features = ["fs", "net", "rt", "rt-multi-thread", "sync"] }
 walkdir = "2"
 
-proxmox-sys = { path = "../proxmox-sys", version = "0.2.0" }
 proxmox-io = { path = "../proxmox-io", version = "1", features = [ "tokio" ] }
 proxmox-time = { path = "../proxmox-time", version = "1" }
+proxmox-lang = { path = "../proxmox-lang", version = "1" }
 
 [dev-dependencies]
 tokio = { version = "1.6", features = [ "macros" ] }
diff --git a/proxmox-async/src/compression.rs b/proxmox-async/src/compression.rs
index b36f291..632a599 100644
--- a/proxmox-async/src/compression.rs
+++ b/proxmox-async/src/compression.rs
@@ -10,7 +10,7 @@ use futures::stream::Stream;
 use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
 
 use proxmox_io::ByteBuffer;
-use proxmox_sys::io_format_err;
+use proxmox_lang::io_format_err;
 
 const BUFFER_SIZE: usize = 8192;
 
diff --git a/proxmox-async/src/io/async_channel_writer.rs b/proxmox-async/src/io/async_channel_writer.rs
index f63648a..697e65b 100644
--- a/proxmox-async/src/io/async_channel_writer.rs
+++ b/proxmox-async/src/io/async_channel_writer.rs
@@ -12,8 +12,7 @@ use tokio::io::AsyncWrite;
 use tokio::sync::mpsc::Sender;
 
 use proxmox_io::ByteBuffer;
-use proxmox_sys::error::io_err_other;
-use proxmox_sys::io_format_err;
+use proxmox_lang::{error::io_err_other, io_format_err};
 
 /// Wrapper around tokio::sync::mpsc::Sender, which implements Write
 pub struct AsyncChannelWriter {
diff --git a/proxmox-http/Cargo.toml b/proxmox-http/Cargo.toml
index 884fe40..40bba3e 100644
--- a/proxmox-http/Cargo.toml
+++ b/proxmox-http/Cargo.toml
@@ -23,6 +23,7 @@ tokio-openssl = { version = "0.6.1", optional = true }
 
 proxmox-sys = { path = "../proxmox-sys", optional = true, version = "0.2.0" }
 proxmox-io = { path = "../proxmox-io", optional = true, version = "1.0.0" }
+proxmox-lang = { path = "../proxmox-lang", optional = true, version = "1.0.0" }
 
 [features]
 default = []
@@ -36,6 +37,7 @@ websocket = [
     "openssl",
     "proxmox-sys",
     "proxmox-io/tokio",
+    "proxmox-lang",
     "tokio/io-util",
     "tokio/sync",
 ]
diff --git a/proxmox-http/src/websocket/mod.rs b/proxmox-http/src/websocket/mod.rs
index cb17776..50477f6 100644
--- a/proxmox-http/src/websocket/mod.rs
+++ b/proxmox-http/src/websocket/mod.rs
@@ -23,7 +23,7 @@ use futures::future::FutureExt;
 use futures::ready;
 
 use proxmox_io::ByteBuffer;
-use proxmox_sys::error::io_err_other;
+use proxmox_lang::error::io_err_other;
 
 // see RFC6455 section 7.4.1
 #[derive(Debug, Clone, Copy)]
diff --git a/proxmox-lang/src/error.rs b/proxmox-lang/src/error.rs
new file mode 100644
index 0000000..2e03c5b
--- /dev/null
+++ b/proxmox-lang/src/error.rs
@@ -0,0 +1,53 @@
+//! A set of macros/helpers for I/O handling. These provide for `std::io::Error` what `anyhow` provides
+//! for `anyhow::Error.`
+
+use std::io;
+
+/// Helper to convert non-system-errors into an `io::Error` or `io::ErrorKind::Other`.
+///
+/// A more convenient way is to use the `io_format_err!` macro.
+pub fn io_err_other<E: ToString>(e: E) -> io::Error {
+    io::Error::new(std::io::ErrorKind::Other, e.to_string())
+}
+
+
+/// Like anyhow's `format_err` but producing a `std::io::Error`.
+#[macro_export]
+macro_rules! io_format_err {
+    ($($msg:tt)+) => {
+        ::std::io::Error::new(::std::io::ErrorKind::Other, format!($($msg)+))
+    };
+}
+
+/// Shortcut to return an `io::Error::last_os_error`.
+///
+/// This is effectively `return Err(::std::io::Error::last_os_error().into());`.
+#[macro_export]
+macro_rules! io_bail_last {
+    () => {{
+        return Err(::std::io::Error::last_os_error().into());
+    }};
+}
+
+/// Like anyhow's `bail` but producing a `std::io::Error`.
+#[macro_export]
+macro_rules! io_bail {
+    ($($msg:tt)+) => {{
+        return Err($crate::io_format_err!($($msg)+));
+    }};
+}
+
+#[doc(hidden)]
+/// Non-panicking assertion: shortcut for returning an `io::Error` if the condition is not met.
+/// Essentially: `if !expr { io_bail_last!() }`.
+///
+/// Note that this uses `errno`, care must be taken not to overwrite it with different value as a
+/// side effect.
+#[macro_export]
+macro_rules! io_assert {
+    ($value:expr) => {
+        if !$value {
+            $crate::io_bail_last!();
+        }
+    };
+}
diff --git a/proxmox-lang/src/lib.rs b/proxmox-lang/src/lib.rs
index f5c6ebe..788165a 100644
--- a/proxmox-lang/src/lib.rs
+++ b/proxmox-lang/src/lib.rs
@@ -6,6 +6,7 @@
 
 mod constnamedbitmap;
 
+pub mod error;
 pub mod ops;
 
 /// Macro to write error-handling blocks (like perl eval {})
diff --git a/proxmox-sys/src/error.rs b/proxmox-sys/src/error.rs
index 3af6038..78f846b 100644
--- a/proxmox-sys/src/error.rs
+++ b/proxmox-sys/src/error.rs
@@ -18,12 +18,7 @@ use std::io;
 use nix::errno::Errno;
 use nix::Error;
 
-/// Helper to convert non-system-errors into an `io::Error` or `io::ErrorKind::Other`.
-///
-/// A more convenient way is to use the `io_format_err!` macro.
-pub fn io_err_other<E: ToString>(e: E) -> io::Error {
-    io::Error::new(std::io::ErrorKind::Other, e.to_string())
-}
+use proxmox_lang::error::io_err_other;
 
 /// This trait should be implemented for error types which can represent system errors. Note that
 /// it is discouraged to try to map non-system errors to with this trait, since users of this trait
diff --git a/proxmox-sys/src/linux/pid.rs b/proxmox-sys/src/linux/pid.rs
index ad5fdc2..07d7163 100644
--- a/proxmox-sys/src/linux/pid.rs
+++ b/proxmox-sys/src/linux/pid.rs
@@ -11,9 +11,9 @@ use nix::sys::stat::Mode;
 use nix::unistd::Pid;
 use nix::NixPath;
 
-use proxmox_lang::c_str;
+use proxmox_lang::{c_str, error::io_err_other};
 
-use crate::error::{io_err_other, SysResult};
+use crate::error::SysResult;
 use crate::linux::procfs::{MountInfo, PidStat};
 use crate::fd::Fd;
 use crate::{c_result, c_try};
diff --git a/proxmox-sys/src/macros.rs b/proxmox-sys/src/macros.rs
index cab6eb3..a76db90 100644
--- a/proxmox-sys/src/macros.rs
+++ b/proxmox-sys/src/macros.rs
@@ -1,47 +1,3 @@
-//! A set of macros for I/O handling. These provide for `std::io::Error` what `anyhow` provides
-//! for `anyhow::Error.`
-
-/// Like anyhow's `format_err` but producing a `std::io::Error`.
-#[macro_export]
-macro_rules! io_format_err {
-    ($($msg:tt)+) => {
-        ::std::io::Error::new(::std::io::ErrorKind::Other, format!($($msg)+))
-    };
-}
-
-/// Shortcut to return an `io::Error::last_os_error`.
-///
-/// This is effectively `return Err(::std::io::Error::last_os_error().into());`.
-#[macro_export]
-macro_rules! io_bail_last {
-    () => {{
-        return Err(::std::io::Error::last_os_error().into());
-    }};
-}
-
-/// Like anyhow's `bail` but producing a `std::io::Error`.
-#[macro_export]
-macro_rules! io_bail {
-    ($($msg:tt)+) => {{
-        return Err($crate::io_format_err!($($msg)+));
-    }};
-}
-
-#[doc(hidden)]
-/// Non-panicking assertion: shortcut for returning an `io::Error` if the condition is not met.
-/// Essentially: `if !expr { io_bail_last!() }`.
-///
-/// Note that this uses `errno`, care must be taken not to overwrite it with different value as a
-/// side effect.
-#[macro_export]
-macro_rules! io_assert {
-    ($value:expr) => {
-        if !$value {
-            $crate::io_bail_last!();
-        }
-    };
-}
-
 /// Roughly equivalent to `nix::Errno::result`. Turns a `-1` into an `io::Error`, while passing
 /// other values through as `Ok(n)`.
 #[macro_export]
diff --git a/proxmox-sys/src/mmap.rs b/proxmox-sys/src/mmap.rs
index cfbf9f7..b296c30 100644
--- a/proxmox-sys/src/mmap.rs
+++ b/proxmox-sys/src/mmap.rs
@@ -7,7 +7,9 @@ use std::{io, mem, ptr};
 
 use nix::sys::mman;
 
-use crate::error::{io_err_other, SysError};
+use proxmox_lang::error::io_err_other;
+
+use crate::error::{SysError};
 
 pub struct Mmap<T> {
     data: *mut T,
-- 
2.30.2