* tar: write directory metadata after file extraction
@ 2019-11-02 18:32 rgl
0 siblings, 0 replies; only message in thread
From: rgl @ 2019-11-02 18:32 UTC (permalink / raw)
To: 9front
[-- 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);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-11-02 18:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-02 18:32 tar: write directory metadata after file extraction rgl
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).