-
-
Save dgl/355840320535bf8ef8b70f2e0722bf65 to your computer and use it in GitHub Desktop.
OpenBSD tar error message filtering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generate a tar archive with an overly long filename, some versions of tar output this unfiltered. | |
package main | |
import ( | |
"archive/tar" | |
"log" | |
"os" | |
) | |
func main() { | |
x, err := os.Create("foo.tar") | |
if err != nil { | |
log.Fatal(err) | |
} | |
tw := tar.NewWriter(x) | |
var files = []struct { | |
Name, Body string | |
}{ | |
{"rgb:ffff/0000/000065535", "printf '\n\\e[;31m\\e#3Well hello '\"$(uname -sr)\"\nprintf '\\n\\e[;31m\\e#4Well hello '\"$(uname -sr)\\n\"\n" }, | |
{"oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\x1b]4;1;red\x1b\\\x1b]4;1;?\x1b\\\x1b[?$p\x1b[8m\x1b[?25l\x1b[>4;2m\x1b[2K\x1b[F\x1b[2K\x1bP$q", ""}, | |
} | |
for _, file := range files { | |
hdr := &tar.Header{ | |
Name: file.Name, | |
Mode: 0755, | |
Size: int64(len(file.Body)), | |
} | |
if err := tw.WriteHeader(hdr); err != nil { | |
log.Fatal(err) | |
} | |
if _, err := tw.Write([]byte(file.Body)); err != nil { | |
log.Fatal(err) | |
} | |
} | |
if err := tw.Close(); err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment