diff --git a/cmd/metha-sync/main.go b/cmd/metha-sync/main.go index 23701a85..5b65309e 100644 --- a/cmd/metha-sync/main.go +++ b/cmd/metha-sync/main.go @@ -41,6 +41,7 @@ var ( extraHeaders xflag.Array // Extra HTTP header. timeout = flag.Duration("T", 30*time.Second, "http client timeout") maxRetries = flag.Int("r", 10, "max number of retries") + keepTemporaryFiles = flag.Bool("k", false, "keep temporary files when interrupted") ) func main() { @@ -123,6 +124,7 @@ func main() { harvest.DailyInterval = *daily harvest.ExtraHeaders = extra harvest.Delay = *delay + harvest.KeepTemporaryFiles = *keepTemporaryFiles log.Printf("harvest: %+v", harvest) if *removeCached { log.Printf("removing already cached files from %s", harvest.Dir()) diff --git a/harvest.go b/harvest.go index 25374ec4..00331cb8 100644 --- a/harvest.go +++ b/harvest.go @@ -67,6 +67,7 @@ type Harvest struct { HourlyInterval bool DailyInterval bool ExtraHeaders http.Header + KeepTemporaryFiles bool Delay int @@ -143,6 +144,11 @@ func (h *Harvest) temporaryFilesSuffix(suffix string) []string { // cleanupTemporaryFiles will remove all temporary files in the harvesting dir. func (h *Harvest) cleanupTemporaryFiles() error { + if h.KeepTemporaryFiles { + log.Printf("keeping %d temporary file(s) under %s", + len(h.temporaryFiles()), h.Dir()) + return nil + } for _, filename := range h.temporaryFiles() { if err := os.Remove(filename); err != nil { if e, ok := err.(*os.PathError); ok && e.Err == syscall.ENOENT {