From df009fccbe1c48f2a9a3f1538d49ce825c03722c Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Sun, 30 Oct 2022 12:47:41 -0500 Subject: [PATCH] path --- ...30-decentralized-identity-middle-ground.md | 2 +- content/posts/2022-10-30-rust-impure-path.md | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 content/posts/2022-10-30-rust-impure-path.md diff --git a/content/posts/2022-10-30-decentralized-identity-middle-ground.md b/content/posts/2022-10-30-decentralized-identity-middle-ground.md index 279a35c..8e08fe0 100644 --- a/content/posts/2022-10-30-decentralized-identity-middle-ground.md +++ b/content/posts/2022-10-30-decentralized-identity-middle-ground.md @@ -1,6 +1,6 @@ +++ title = "Decentralized Identity, a Middle Ground" -date = 2022-10-30 +date = 2022-10-30T03:04:51-05:00 logseq = true +++ diff --git a/content/posts/2022-10-30-rust-impure-path.md b/content/posts/2022-10-30-rust-impure-path.md new file mode 100644 index 0000000..70fdd2b --- /dev/null +++ b/content/posts/2022-10-30-rust-impure-path.md @@ -0,0 +1,36 @@ ++++ +title = "Rust's Impure Path" +date = 2022-10-30T04:04:51-05:00 ++++ + +I work on [garbage], a project that touches the filesystem a lot. Because of +this, I'd really like to control when and where these filesystem accesses +happen. + +[garbage]: https://git.sr.ht/~mzhang/garbage + +The Rust standard library has a `fs` module, which I expect to _exclusively_ +contain filesystem access primitives. But actually a lot of the functionality +also gets leaked into `std::path::Path`. + +In my ideal world, `Path` only deals with the data in a path, not its +interaction with the filesystem. So it should never be able to check whether or +not a path [exists], for example, or if a path [is a symlink][is_symlink]. Those +should be delegated to something within `fs`. + +[exists]: https://doc.rust-lang.org/stable/std/path/struct.Path.html#method.exists +[is_symlink]: https://doc.rust-lang.org/stable/std/path/struct.Path.html#method.is_symlink + +In addition, many of these functions automatically resolve symlinks, without +built-in ways of achieving the same functionality without resolving symlinks, so +I ended up having to fill those in myself. For example, I really just expect +[`canonicalize`] to be an in-memory manipulation of path components. + +[`canonicalize`]: https://doc.rust-lang.org/stable/std/path/struct.Path.html#method.canonicalize + +Honestly, I've got to give it to Python's [pathlib], which solves the problems I +noted above. It splits the path API into `Path` and `PurePath`, the latter of +which does not make any IO accesses. It also provides non-symlink-resolving and +symlink-resolving variants of converting to absolute paths. + +[pathlib]: https://docs.python.org/3/library/pathlib.html