~sircmpwn/rc-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH v2] interp: implement ~user

Curtis Arthaud <uku82@gmx.fr>
Details
Message ID
<20231030141717.8733-2-uku82@gmx.fr>
DKIM signature
missing
Download raw message
Patch: +34 -4
Signed-off-by: Curtis Arthaud <uku82@gmx.fr>
---
 interp/value.ha | 38 ++++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/interp/value.ha b/interp/value.ha
index 1ac8653..4ab2372 100644
--- a/interp/value.ha
+++ b/interp/value.ha
@@ -9,6 +9,8 @@ use path;
use rt;
use strconv;
use strings;
use unix::passwd;
use unix;

// A value object.
// TODO: s/[]value/[]str/g
@@ -97,11 +99,39 @@ export fn expand(state: *state, val: *ast::value, glob: bool) (value | error) =
};

fn expand_tilde(pattern: str) str = {
	const home = os::getenv("HOME") as str;
	let buf = path::init(pattern)!;
	path::popprefix(&buf, "~")!;
	path::prepend(&buf, home)!;
	return strings::dup(path::string(&buf));

	let iter = path::iter(&buf);
	const prefix = match (path::nextiter(&iter)) {
		case let s: str =>
			yield s;
		case =>
			abort();
	};
	if (prefix == "~") {
		const pw = passwd::getuid(unix::getuid()) as passwd::pwent;
		defer passwd::pwent_finish(&pw);
		const home = strings::dup(pw.homedir);
		path::popprefix(&buf, "~")!;
		path::prepend(&buf, home)!;
	} else {
		const user = strings::dup(strings::ltrim(prefix, '~'));
		match (passwd::getuser(user)) {
		case void =>
			void;
		case =>
			path::popprefix(&buf, prefix)!;
			path::prepend(&buf, user)!;
			path::prepend(&buf, "/home")!;
		};
	};

	const s = path::string(&buf);
	if (strings::hassuffix(pattern, '/')) {
		return strings::join("", s, "/");
	} else {
		return strings::dup(s);
	};
};

fn expand_glob(pattern: str) (value | error) = {
--
2.42.0
Details
Message ID
<CWLU97OQFBCV.2LN85OE34IG9W@taiga>
In-Reply-To
<20231030141717.8733-2-uku82@gmx.fr> (view parent)
DKIM signature
missing
Download raw message
It looks like this has the same problem.
Reply to thread Export thread (mbox)