Skip to content
Snippets Groups Projects
Commit 2d77883b authored by Fredrik Noring's avatar Fredrik Noring
Browse files

Added Marcus Comstedt's root/root tar filter.

Rev: bin/install.pike:1.67
Rev: bin/mkpackage.pike:1.5
Rev: bin/tarfilter.pike:1.1
parent 2dcc2969
No related branches found
No related tags found
No related merge requests found
......@@ -420,6 +420,11 @@ string translate(string filename, mapping translator)
combine_path(translate(dirname(filename),translator),basename(filename));
};
void tarfilter(string filename)
{
((program)combine_path(__FILE__, "..", "tarfilter"))()->
main(3, ({ "tarfilter", filename, filename }));
}
void do_export()
{
......@@ -604,6 +609,9 @@ done
tararg="rf";
}
status("Filtering to root/root ownership", tmpname+".tar");
tarfilter(tmpname+".tar");
status("Creating",tmpname+".tar.gz");
Process.create_process(({"gzip","-9",tmpname+".tar"}))->wait();
......@@ -615,6 +623,9 @@ done
Process.create_process( ({ "tar","cf", export_base_name})+ to_export)
->wait();
status("Filtering to root/root ownership", export_base_name);
tarfilter(export_base_name);
chmod(export_base_name,0755);
status("Cleaning up","");
......
......@@ -142,6 +142,10 @@ class Package
cd(original_wd);
}
// Filter to root/root ownership.
((program)combine_path(__FILE__, "..", "tarfilter"))()->
main(3, ({ "tarfilter", package_filename, package_filename }));
chmod(package_filename, 0755);
rmrf("#!", setup_filename);
......
#!/usr/local/bin/pike
//
// Filters a tar file applying root/root ownership.
//
void copydata(Stdio.File in, Stdio.File out, int size)
{
while(size>0) {
string s = in->read((size>8192? 8192 : size));
if(s == "") {
werror("READ ERROR on input\n");
exit(1);
}
out->write(s);
size -= strlen(s);
}
}
void doit(Stdio.File in, Stdio.File out)
{
for(;;) {
string s = in->read(512);
if(s == "")
break;
if(strlen(s) != 512) {
werror("READ ERROR on input\n");
exit(1);
}
if(s-"\0" == "") {
out->write(s);
continue;
}
array a =
array_sscanf(s, "%100s%8s%8s%8s%12s%12s%8s%c%100s%8s%32s%32s%8s%8s");
int csum, size;
sscanf(a[4], "%o", size);
sscanf(a[6], "%o", csum);
s=s[..147]+" "+s[156..];
if(`+(@values(s[..511])) != csum) {
werror("CHECKSUM ERROR on input!\n");
exit(1);
}
a[2] = " 0 \0";
a[3] = " 0 \0";
if((a[9]/"\0")[0]-" " == "ustar") {
a[10] = "root\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
a[11] = "root\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
}
a[6] = " ";
s = sprintf("%100s%8s%8s%8s%12s%12s%8s%c%100s%8s%32s%32s%8s%8s", @a)+
s[345..];
out->write(s[..147]+sprintf("%07o\0", `+(@values(s[..511])))+s[156..]);
copydata(in, out, size);
if(size & 511)
copydata(in, out, 512-(size & 511));
}
}
int main(int argc, array(string) argv)
{
Stdio.File s = Stdio.File("stdin");
Stdio.File d = Stdio.File("stdout");
if(argc == 3)
{
s = Stdio.File(argv[1], "r");
d = Stdio.File(argv[2]+".tmp", "cwt");
}
doit(s, d);
if(argc == 3)
{
d->close();
s->close();
if(!mv(argv[2]+".tmp", argv[2]))
{
werror("FATAL! mv(%O, %O) failed.", argv[2], argv[2]);
exit(1);
}
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment