summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 86da1c5)
raw | patch | inline | side by side (parent: 86da1c5)
author | Rene Scharfe <rene.scharfe@lsrfire.ath.cx> | |
Sat, 25 Mar 2006 22:21:07 +0000 (23:21 +0100) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Sun, 26 Mar 2006 00:40:34 +0000 (16:40 -0800) |
... to store parts of the path, if possible. This allows us to avoid
writing extended headers in certain cases (long pathes can only be
split at '/' chars).
Also adds a file to the test repo with a 100 chars long directory name.
Even old versions of tar that don't understand POSIX extended headers
should be able to handle this testcase.
Btw.: The longest path in the kernel tree currently has 70 chars.
Together with a 30 chars long prefix this would already cross the
field limit of 100 chars.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <junkio@cox.net>
writing extended headers in certain cases (long pathes can only be
split at '/' chars).
Also adds a file to the test repo with a 100 chars long directory name.
Even old versions of tar that don't understand POSIX extended headers
should be able to handle this testcase.
Btw.: The longest path in the kernel tree currently has 70 chars.
Together with a 30 chars long prefix this would already cross the
field limit of 100 chars.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <junkio@cox.net>
t/t5000-tar-tree.sh | patch | blob | history | |
tar-tree.c | patch | blob | history |
diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh
index adc5e937de1a4b28b9556ca00fdfbc95dead70d7..278eb6670116d0036413a81fc129615974458e5d 100755 (executable)
--- a/t/t5000-tar-tree.sh
+++ b/t/t5000-tar-tree.sh
mkdir a/bin &&
cp /bin/sh a/bin &&
ln -s a a/l1 &&
+ (p=long_path_to_a_file && cd a &&
+ for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
+ echo text >file_with_long_path) &&
(cd a && find .) | sort >a.lst'
test_expect_success \
diff --git a/tar-tree.c b/tar-tree.c
index 11bbc81e36d6e3ac16ff7f113b01d9d651f7edd3..efab2b5420af5225a0ebb4dbecd37252ed7ef1ff 100644 (file)
--- a/tar-tree.c
+++ b/tar-tree.c
return chksum;
}
+static int get_path_prefix(const struct strbuf *path, int maxlen)
+{
+ int i = path->len;
+ if (i > maxlen)
+ i = maxlen;
+ while (i > 0 && path->buf[i] != '/')
+ i--;
+ return i;
+}
+
static void write_entry(const unsigned char *sha1, struct strbuf *path,
unsigned int mode, void *buffer, unsigned long size)
{
return;
}
if (path->len > sizeof(header.name)) {
- sprintf(header.name, "%s.data", sha1_to_hex(sha1));
- strbuf_append_ext_header(&ext_header, "path",
- path->buf, path->len);
+ int plen = get_path_prefix(path, sizeof(header.prefix));
+ int rest = path->len - plen - 1;
+ if (plen > 0 && rest <= sizeof(header.name)) {
+ memcpy(header.prefix, path->buf, plen);
+ memcpy(header.name, path->buf + plen + 1, rest);
+ } else {
+ sprintf(header.name, "%s.data",
+ sha1_to_hex(sha1));
+ strbuf_append_ext_header(&ext_header, "path",
+ path->buf, path->len);
+ }
} else
memcpy(header.name, path->buf, path->len);
}