diff --git a/main.go b/main.go index f9669e8..882f35d 100644 --- a/main.go +++ b/main.go @@ -93,6 +93,7 @@ var ( mirror = flag.String("mirror", "https://dist.torproject.org/torbrowser/", "Mirror to use") solidarity = flag.Bool("onion", false, "Serve an onion site which shows some I2P propaganda") torrent = flag.Bool("torrent", tbget.TorrentReady(), "Create a torrent of the downloaded files and seed it over I2P using an Open Tracker") + destruct = flag.Bool("destruct", false, "Destructively delete the working directory when finished") /*ptop = flag.Bool("p2p", false, "Use bittorrent over I2P to download the initial copy of Tor Browser")*/ ) @@ -121,6 +122,9 @@ func main() { if *snowflake { go Snowflake() } + if *destruct { + defer OverwriteDirectoryContents(*directory) + } tbget.WORKING_DIR = *directory if filename == "i2pbrowser" { log.Println("Starting I2P in Tor Browser") diff --git a/rmdir.go b/rmdir.go new file mode 100644 index 0000000..2984453 --- /dev/null +++ b/rmdir.go @@ -0,0 +1,32 @@ +package main + +import ( + "log" + "os" + "path/filepath" +) + +func OverwriteDirectoryContents(directory string) { + //walk the contents of directory recursively + //and zero-out the files to the length of the file + filepath.Walk(directory, func(path string, info os.FileInfo, err error) error { + go func() { + if err != nil { + log.Println("Error:", err) + } + if info.IsDir() { + log.Println("Error:", err) + } + file, err := os.OpenFile(path, os.O_RDWR, 0) + if err != nil { + log.Println("Error:", err) + } + defer file.Close() + bytes := info.Size() + file.Truncate(0) + file.Write(make([]byte, bytes)) + log.Println("Error:", err) + }() + return nil + }) +}