Re: [dev] tar filename handling

2022-08-01 Thread Страхиња Радић
On 22/08/01 09:30, Quentin Rameau wrote:
> Andrew has posted a patch (on hackers@ on may first) for this
> that nobody had time to review yet. :/
> I suggest you try it, that should fix your issue.

Ah, I'm not subscribed on that list (yet?). Anyway, I tested my patch on my use 
case and it behaves correctly so far, so I leave you guys to decide whether to 
review/include it or not.

In the meantime, I have posted another patch, which adds a -n option 
(equivalent of --no-recursion) for your consideration.


signature.asc
Description: PGP signature


Re: [dev] tar filename handling

2022-08-01 Thread Quentin Rameau
Hi Страхиња,

> The path that failed was
> 
> ./sucks/lib/python3.9/site-packages/docutils/parsers/__pycache__/commonmark_wrapper.cpython-39.opt-1.pyc
> 
> which is 104 characters long. On further inspection, it seems that the prefix 
> field is taken into account with -x and -t ("small dance..."):

Andrew has posted a patch (on hackers@ on may first) for this
that nobody had time to review yet. :/
I suggest you try it, that should fix your issue.



Re: [dev] tar filename handling

2022-08-01 Thread Страхиња Радић
I have made the necessary change, you can review my patch here:

https://git.sr.ht/~strahinja/sbase/tree/master/item/patches/0001-Split-path-into-prefix-name-on-c.patch

I also attached it to this message.
From d91f1b0315ca3a0d584f8ac7c2e8ef16cc7493c4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=A1=D1=82=D1=80=D0=B0=D1=85=D0=B8=D1=9A=D0=B0=20=D0=A0?=
 =?UTF-8?q?=D0=B0=D0=B4=D0=B8=D1=9B?= 
Date: Mon, 1 Aug 2022 09:12:03 +0200
Subject: [PATCH] Split path into prefix + name on -c
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Страхиња Радић 
---
 tar.c | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/tar.c b/tar.c
index d3a9f3b..4c35102 100644
--- a/tar.c
+++ b/tar.c
@@ -180,6 +180,7 @@ static int
 archive(const char *path)
 {
 	char b[BLKSIZ];
+	char *split;
 	struct group *gr;
 	struct header *h;
 	struct passwd *pw;
@@ -187,6 +188,7 @@ archive(const char *path)
 	size_t chksum, i;
 	ssize_t l, r;
 	int fd = -1;
+	int slen, plen;
 
 	if (lstat(path, ) < 0) {
 		weprintf("lstat %s:", path);
@@ -201,7 +203,19 @@ archive(const char *path)
 
 	h = (struct header *)b;
 	memset(b, 0, sizeof(b));
-	estrlcpy(h->name,path,sizeof(h->name));
+	if ((split = strrchr(path, '/')) > path)
+	{
+		plen = strlen(path);
+		slen = (int)(split - path);
+		if (snprintf(h->prefix, sizeof(h->prefix), "%.*s",
+			slen, path) >= sizeof(h->prefix))
+			eprintf("snprintf: input string too long\n");
+		if (snprintf(h->name, sizeof(h->name), "%.*s",
+			(int)(plen-slen-1), path+slen+1) >= sizeof(h->name))
+			eprintf("snprintf: input string too long\n");
+	}
+	else
+		estrlcpy(h->name, path,   sizeof(h->name));
 	putoctal(h->mode,(unsigned)st.st_mode & 0777, sizeof(h->mode));
 	putoctal(h->uid, (unsigned)st.st_uid, sizeof(h->uid));
 	putoctal(h->gid, (unsigned)st.st_gid, sizeof(h->gid));
-- 
2.37.1



signature.asc
Description: PGP signature


[dev] tar filename handling

2022-07-31 Thread Страхиња Радић
I was using suckless tar to create an archive of a Python package, and hit a 
limit. When checking out the code, I noticed that the name of the file is 100 
characters long, however there is also the prefix field which is 155 characters 
long, and the actual path should be combined from prefix (if present) + name.

https://git.suckless.org/sbase/file/tar.c.html#l36

The path that failed was

./sucks/lib/python3.9/site-packages/docutils/parsers/__pycache__/commonmark_wrapper.cpython-39.opt-1.pyc

which is 104 characters long. On further inspection, it seems that the prefix 
field is taken into account with -x and -t ("small dance..."):

https://git.suckless.org/sbase/file/tar.c.html#l460

but not with -c:

https://git.suckless.org/sbase/file/tar.c.html#l204

I just wanted to know if this is planned for a future update. If not, I'd like 
to try to implement long (>100) path splitting for -c.


signature.asc
Description: PGP signature