From: rgl@antares-labs.eu
To: 9front@9front.org
Subject: tar: write directory metadata after file extraction
Date: Sat, 2 Nov 2019 19:32:33 +0100 [thread overview]
Message-ID: <AA5BAE62A5C074D149164AEF805412E6@antares-labs.eu> (raw)
[-- Attachment #1: Type: text/plain, Size: 110 bytes --]
hi community,
i implemented the expected behavior for
directories when using the T option.
cheers,
-rodri
[-- Attachment #2: Type: text/plain, Size: 1923 bytes --]
diff -r 1d6a49358dd8 sys/src/cmd/tar.c
--- a/sys/src/cmd/tar.c Sat Nov 02 14:17:34 2019 +0100
+++ b/sys/src/cmd/tar.c Sat Nov 02 19:04:49 2019 +0100
@@ -129,6 +129,13 @@
int open;
} Pushstate;
+typedef struct {
+ Hdr *hp;
+ int fd;
+ long mtime;
+ ulong mode;
+} Leftover;
+
#define OTHER(rdwr) ((rdwr) == Rd? Wr: Rd)
static int fixednblock;
@@ -153,6 +160,9 @@
static Hdr *tpblk, *endblk;
static Hdr *curblk;
+static Leftover *scraps;
+static int nscrap;
+
static void
usage(void)
{
@@ -238,6 +248,40 @@
return docompress? comps: nil;
}
+/* leftover directories management */
+
+static void wrmeta(int, Hdr*, long, int);
+
+static void
+pushleftover(Hdr *hp, int fd, long mtime, ulong mode)
+{
+ Leftover *l;
+
+ /* looking for a better alloc strategy */
+ scraps = realloc(scraps, ++nscrap*sizeof(Leftover));
+ if(scraps == nil)
+ sysfatal("realloc: %r");
+ l = scraps+(nscrap-1);
+ l->hp = hp;
+ l->fd = fd;
+ l->mtime = mtime;
+ l->mode = mode;
+}
+
+static void
+flushleftovers(void)
+{
+ Leftover *l;
+
+ while(nscrap-- > 0){
+ l = scraps+nscrap;
+ wrmeta(l->fd, l->hp, l->mtime, l->mode);
+ close(l->fd);
+ }
+ free(scraps);
+ scraps = nil;
+}
+
/*
* push a filter, cmd, onto fd. if input, it's an input descriptor.
* returns a descriptor to replace fd, or -1 on error.
@@ -1182,14 +1226,14 @@
copyfromar(ar, fd, fname, blksleft, bytes);
- /* touch up meta data and close */
+ /* touch up meta data and close, dirs are saved for later */
if (fd >= 0) {
- /*
- * directories should be wstated *after* we're done
- * creating files in them, but we don't do that.
- */
if (settime)
- wrmeta(fd, hp, mtime, mode);
+ if (dir) {
+ pushleftover(hp, fd, mtime, mode);
+ return;
+ } else
+ wrmeta(fd, hp, mtime, mode);
close(fd);
}
}
@@ -1275,6 +1319,7 @@
else
skip(ar, hp, longname);
}
+ flushleftovers();
if (comp)
return pushclose(&ps);
reply other threads:[~2019-11-02 18:32 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AA5BAE62A5C074D149164AEF805412E6@antares-labs.eu \
--to=rgl@antares-labs.eu \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).