[-] MoSal@programming.dev 3 points 3 days ago* (last edited 3 days ago)

Reading your comment, I immediately thought there must be an S3 FUSE wrapper out there, and quickly found this:

https://github.com/s3fs-fuse/s3fs-fuse

[-] MoSal@programming.dev 9 points 3 months ago

I didn't realize this was posted here.

Allow me to copy my comment from another thread:


// Don't bail on the first error, but remember the worst one.
let mut worst = 0;
for file in files {
    if let Err(e) = chmod_one(file) {
        worst = worst.max(e.exit_code());
    }
}
process::exit(worst);

This is not rustic, I feel.

files.iter()
  .map(chmod_one)
  .filter_map(Result::err)

is more like it.

From there, you can next() for first error, last() for last error, or fold() for max error, or collect() if you need to save all errors.


And no, static compilation doesn’t help here, because get_user_by_name goes through NSS, which dlopens libnss_* modules at runtime regardless of whether your binary is statically linked.

This is not true in musl systems. I just quickly checked in a Chimera rootfs (which has a system dynamic musl libc btw).

I believe the described dlopening is one of the well known reasons why GNU libc is not suitable for static linking, unlike musl!

In Arch, this indeed loads /usr/lib/libnss_systemd.so.2.

Everyone can test this with strace id 2>&1 | egrep 'open.*\.so'.

[-] MoSal@programming.dev 7 points 3 months ago* (last edited 3 months ago)
// Don't bail on the first error, but remember the worst one.
let mut worst = 0;
for file in files {
    if let Err(e) = chmod_one(file) {
        worst = worst.max(e.exit_code());
    }
}
process::exit(worst);

This is not rustic, I feel.

files.iter()
  .map(chmod_one)
  .filter_map(Result::err)

is more like it.

From there, you can next() for first error, last() for last error, or fold() for max error, or collect() if you need to save all errors.


And no, static compilation doesn’t help here, because get_user_by_name goes through NSS, which dlopens libnss_* modules at runtime regardless of whether your binary is statically linked.

This is not true in musl systems. I just quickly checked in a Chimera rootfs (which has a system dynamic musl libc btw).

I believe the described dlopening is one of the well known reasons why GNU libc is not suitable for static linking, unlike musl!

In Arch, this indeed loads /usr/lib/libnss_systemd.so.2.

Everyone can test this with strace id 2>&1 | egrep 'open.*\.so'.

[-] MoSal@programming.dev 4 points 6 months ago

It was just a quick solution showing how to do it with one macro and zero dependencies, utilizing the power of meta variables. It probably can be made nicer.

Side Note: It's not directly relevant/needed here, but this also shows that maybe a theoretical $reverse{} meta variable can be useful with repeated patterns, to in this case generate the variants in the expected order.

[-] MoSal@programming.dev 2 points 6 months ago* (last edited 6 months ago)

(slightly edited from initial version)

#![feature(macro_metavar_expr_concat)]
#![feature(macro_metavar_expr)]

macro_rules! gen_enums {
    ([$($name:ident)+]) => {
        gen_enums!(${count($name)}: [$($name)+]);
    };
    ($n:literal: [$($name:ident)+]) => {
        enum ${concat(Position, $n)} { $($name,)+ }
    };
    ($name:ident, $($tail:ident,)*) => {
        gen_enums!([$name $($tail)*]);
        gen_enums!($($tail,)*);
    };
    () => {};
}
[-] MoSal@programming.dev 4 points 9 months ago

This, and similar posts discussing the same subject, seem to fail to realize that you can trivially implement your own back-off strategy using Mutex::try_lock(). This can have significant performance implications in use-cases where absolute low latency is not required.

I rarely see this get mentioned, although I think I did see it once or twice.

A shout out to the spin crate too, which has a lot of options that may interest people explicitly supported/exposed. It also supports no_std which can be immensely useful in some use-cases.

[-] MoSal@programming.dev 1 points 9 months ago

You know repository info is just metadata, right? You can set it to anything.

And you could have grabbed the actually published versions easily, before randomly fear mongering against a random forked crate.

#/bin/bash

crate_name = $1

while read url; do
  curl -L $url | bsdtar xfv -
done <<(curl -L https://crates.io/api/v1/crates/$%7Bcrate_name%7D/versions | jq -r '"https://crates.io/" +.versions[].dl_path')

Run this for both crates, and you will have these crates locally at:

fnmatch-regex2-0.3.0
fnmatch-regex2-0.4.0
fnmatch-regex-0.1.0
fnmatch-regex-0.2.0
fnmatch-regex-0.2.1

from there

diff -ru fnmatch-regex-0.2.1 fnmatch-regex2-0.4.0

or du -ruN if you want the full content of Cargo.lock in the diff 😉

diff -ru fnmatch-regex-0.2.1/.cargo_vcs_info.json fnmatch-regex2-0.4.0/.cargo_vcs_info.json
***
fnmatch-regex-0.2.1/.cargo_vcs_info.json	1970-01-01 02:00:01.000000000 +0200
+++ fnmatch-regex2-0.4.0/.cargo_vcs_info.json	1970-01-01 02:00:01.000000000 +0200
@@ -1,6 +1,6 @@
 {
   "git": {
-    "sha1": "73bd95ec60b4f9ee3ab2ad8d3475e005df7ddc4a"
+    "sha1": "2f810aaeef8eefcee722a29822e46c4091940c8b"
   },
   "path_in_vcs": ""
 }
\ No newline at end of file
diff -ru fnmatch-regex-0.2.1/.editorconfig fnmatch-regex2-0.4.0/.editorconfig
***
fnmatch-regex-0.2.1/.editorconfig	2006-07-24 04:21:28.000000000 +0300
+++ fnmatch-regex2-0.4.0/.editorconfig	2006-07-24 04:21:28.000000000 +0300
@@ -1,6 +1,6 @@
 # https://editorconfig.org/
 #
-# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>
+# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>, Martin Bammer <mrbm74@gmail.com>
 # SPDX-License-Identifier: BSD-2-Clause
 
 root = true
diff -ru fnmatch-regex-0.2.1/.gitignore fnmatch-regex2-0.4.0/.gitignore
***
fnmatch-regex-0.2.1/.gitignore	2006-07-24 04:21:28.000000000 +0300
+++ fnmatch-regex2-0.4.0/.gitignore	2006-07-24 04:21:28.000000000 +0300
@@ -5,3 +5,4 @@
 
 site/
 target/
+Cargo.lock
diff -ru fnmatch-regex-0.2.1/.readthedocs.yaml fnmatch-regex2-0.4.0/.readthedocs.yaml
***
fnmatch-regex-0.2.1/.readthedocs.yaml	2006-07-24 04:21:28.000000000 +0300
+++ fnmatch-regex2-0.4.0/.readthedocs.yaml	2006-07-24 04:21:28.000000000 +0300
@@ -1,4 +1,4 @@
-# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>
+# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>, Martin Bammer <mrbm74@gmail.com>
 # SPDX-License-Identifier: BSD-2-Clause
 
 version: 2
Only in fnmatch-regex-0.2.1: .reuse
Only in fnmatch-regex2-0.4.0: Cargo.lock
diff -ru fnmatch-regex-0.2.1/Cargo.toml fnmatch-regex2-0.4.0/Cargo.toml
***
fnmatch-regex-0.2.1/Cargo.toml	1970-01-01 02:00:01.000000000 +0200
+++ fnmatch-regex2-0.4.0/Cargo.toml	1970-01-01 02:00:01.000000000 +0200
@@ -10,12 +10,16 @@
 # See Cargo.toml.orig for the original contents.
 
 [package]
-edition = "2021"
-rust-version = "1.58"
-name = "fnmatch-regex"
-version = "0.2.1"
-authors = ["Peter Pentchev <roam@ringlet.net>"]
+edition = "2024"
+rust-version = "1.85"
+name = "fnmatch-regex2"
+version = "0.4.0"
+authors = [
+    "Peter Pentchev <roam@ringlet.net>",
+    "Martin Bammer <mrbm74@gmail.com>",
+]
 build = false
+autolib = false
 autobins = false
 autoexamples = false
 autotests = false
@@ -34,23 +38,23 @@
     "parser-implementations",
 ]
 license = "BSD-2-Clause"
-repository = "https://gitlab.com/ppentchev/fnmatch-regex-rs"
+repository = "https://gitlab.com/brmmm3/fnmatch-regex2-rs"
 
 [lib]
-name = "fnmatch_regex"
+name = "fnmatch_regex2"
 path = "src/lib.rs"
 
 [dependencies.anyhow]
-version = "1.0.69"
+version = "1.0"
 
 [dependencies.itertools]
-version = ">= 0.10.3, < 0.14"
+version = "0.14"
 
 [dependencies.regex]
-version = "1.7.1"
+version = "1.11"
 
 [dependencies.thiserror]
-version = "1.0.38"
+version = "2.0"
 
 [dev-dependencies.rstest]
-version = ">= 0.17, < 0.24"
+version = "0.25"
diff -ru fnmatch-regex-0.2.1/Cargo.toml.orig fnmatch-regex2-0.4.0/Cargo.toml.orig
***
fnmatch-regex-0.2.1/Cargo.toml.orig	2006-07-24 04:21:28.000000000 +0300
+++ fnmatch-regex2-0.4.0/Cargo.toml.orig	2006-07-24 04:21:28.000000000 +0300
@@ -1,24 +1,21 @@
-# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>
-# SPDX-License-Identifier: BSD-2-Clause
-
 [package]
-name = "fnmatch-regex"
-version = "0.2.1"
-rust-version = "1.58"
-authors = ["Peter Pentchev <roam@ringlet.net>"]
-edition = "2021"
+name = "fnmatch-regex2"
+version = "0.4.0"
+authors = ["Peter Pentchev <roam@ringlet.net>", "Martin Bammer <mrbm74@gmail.com>"]
+edition = "2024"
 description = "Convert a glob-style pattern to a regular expression."
 readme = "README.md"
-repository = "https://gitlab.com/ppentchev/fnmatch-regex-rs"
+repository = "https://gitlab.com/brmmm3/fnmatch-regex2-rs"
 license = "BSD-2-Clause"
 categories = ["encoding", "filesystem", "parser-implementations"]
 keywords = ["fnmatch", "glob", "pattern", "regex"]
+rust-version = "1.85"
 
 [dependencies]
-anyhow = "1.0.69"
-itertools = ">= 0.10.3, < 0.14"
-regex = "1.7.1"
-thiserror = "1.0.38"
+anyhow = "1.0"
+itertools = "0.14"
+regex = "1.11"
+thiserror = "2.0"
 
 [dev-dependencies]
-rstest = ">= 0.17, < 0.24"
+rstest = "0.25"
Only in fnmatch-regex2-0.4.0: NEWS.md
Only in fnmatch-regex-0.2.1: docs
diff -ru fnmatch-regex-0.2.1/mkdocs.yml fnmatch-regex2-0.4.0/mkdocs.yml
***
fnmatch-regex-0.2.1/mkdocs.yml	2006-07-24 04:21:28.000000000 +0300
+++ fnmatch-regex2-0.4.0/mkdocs.yml	2006-07-24 04:21:28.000000000 +0300
@@ -1,4 +1,4 @@
-# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>
+# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>, Martin Bammer <mrbm74@gmail.com>
 # SPDX-License-Identifier: BSD-2-Clause
 
 theme:
diff -ru fnmatch-regex-0.2.1/pyproject.toml fnmatch-regex2-0.4.0/pyproject.toml
***
fnmatch-regex-0.2.1/pyproject.toml	2006-07-24 04:21:28.000000000 +0300
+++ fnmatch-regex2-0.4.0/pyproject.toml	2006-07-24 04:21:28.000000000 +0300
@@ -1,4 +1,4 @@
-# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>
+# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>, Martin Bammer <mrbm74@gmail.com>
 # SPDX-License-Identifier: BSD-2-Clause
 
 [tool.publync.format.version]
diff -ru fnmatch-regex-0.2.1/requirements/docs.txt fnmatch-regex2-0.4.0/requirements/docs.txt
***
fnmatch-regex-0.2.1/requirements/docs.txt	2006-07-24 04:21:28.000000000 +0300
+++ fnmatch-regex2-0.4.0/requirements/docs.txt	2006-07-24 04:21:28.000000000 +0300
@@ -1,4 +1,4 @@
-# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>
+# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>, Martin Bammer <mrbm74@gmail.com>
 # SPDX-License-Identifier: BSD-2-Clause
 
 mkdocs >= 1.4.2, < 2
diff -ru fnmatch-regex-0.2.1/run-clippy.sh fnmatch-regex2-0.4.0/run-clippy.sh
***
fnmatch-regex-0.2.1/run-clippy.sh	2006-07-24 04:21:28.000000000 +0300
+++ fnmatch-regex2-0.4.0/run-clippy.sh	2006-07-24 04:21:28.000000000 +0300
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>
+# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>, Martin Bammer <mrbm74@gmail.com>
 # SPDX-License-Identifier: BSD-2-Clause
 
 
diff -ru fnmatch-regex-0.2.1/src/glob.rs fnmatch-regex2-0.4.0/src/glob.rs
***
fnmatch-regex-0.2.1/src/glob.rs	2006-07-24 04:21:28.000000000 +0300
+++ fnmatch-regex2-0.4.0/src/glob.rs	2006-07-24 04:21:28.000000000 +0300
@@ -37,7 +37,7 @@
 //! # use std::error::Error;
 //!
 //! # fn main() -> Result<(), Box<dyn Error>> {
-//! let re_name = fnmatch_regex::glob_to_regex("linux-[0-9]*-{generic,aws}")?;
+//! let re_name = fnmatch_regex2::glob_to_regex("linux-[0-9]*-{generic,aws}")?;
 //! for name in &[
 //!     "linux-5.2.27b1-generic",
 //!     "linux-4.0.12-aws",
@@ -60,7 +60,7 @@
 
 use anyhow::anyhow;
 use itertools::{Either, Itertools as _};
-use regex::Regex;
+use regex::{Regex, RegexBuilder};
 
 use crate::error::Error as FError;
 
@@ -572,3 +572,24 @@
     let re_pattern = parser.flatten_ok().collect::<Result<Vec<_>, _>>()?.join("");
     Regex::new(&re_pattern).map_err(|err| FError::InvalidRegex(re_pattern, err))
 }
+
+/// Parse a shell glob-like pattern into a regular expression.
+///
+/// See the module-level documentation for a description of the pattern
+/// features supported.
+///
+/// # Errors
+/// Most of the [`crate::error::Error`] values, mostly syntax errors in
+/// the specified glob pattern.
+#[allow(clippy::missing_inline_in_public_items)]
+pub fn glob_to_regex_ext(pattern: &str, ignore_case: bool) -> Result<Regex, FError> {
+    let parser = GlobIterator {
+        pattern: pattern.chars(),
+        state: State::Start,
+    };
+    let re_pattern = parser.flatten_ok().collect::<Result<Vec<_>, _>>()?.join("");
+    RegexBuilder::new(&re_pattern)
+        .case_insensitive(ignore_case)
+        .build()
+        .map_err(|err| FError::InvalidRegex(re_pattern, err))
+}
diff -ru fnmatch-regex-0.2.1/src/lib.rs fnmatch-regex2-0.4.0/src/lib.rs
***
fnmatch-regex-0.2.1/src/lib.rs	2006-07-24 04:21:28.000000000 +0300
+++ fnmatch-regex2-0.4.0/src/lib.rs	2006-07-24 04:21:28.000000000 +0300
@@ -15,7 +15,9 @@
 pub mod error;
 pub mod glob;
 
-pub use glob::glob_to_regex;
+pub use glob::{glob_to_regex, glob_to_regex_ext};
+
+pub use regex::Regex;
 
 #[cfg(test)]
 pub mod tests;
diff -ru fnmatch-regex-0.2.1/tox.ini fnmatch-regex2-0.4.0/tox.ini
***
fnmatch-regex-0.2.1/tox.ini	2006-07-24 04:21:28.000000000 +0300
+++ fnmatch-regex2-0.4.0/tox.ini	2006-07-24 04:21:28.000000000 +0300
@@ -1,4 +1,4 @@
-# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>
+# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>, Martin Bammer <mrbm74@gmail.com>
 # SPDX-License-Identifier: BSD-2-Clause
 
 [tox]

And you do know that the docs.rs service itself generates docs from published crates in crates.io, and that is the exactly same code you see when viewing sources there, right?

[-] MoSal@programming.dev 3 points 1 year ago

Do you mean a global allocator?

MoSal

joined 1 year ago