in main/cmds.go [221:253]
func downloadFiles(ctx *log.Context, dir string, cfg handlerSettings) error {
// - prepare the output directory for files and the command output
// - create the directory if missing
ctx.Log("event", "creating output directory", "path", dir)
if err := os.MkdirAll(dir, 0700); err != nil {
return errors.Wrap(err, "failed to prepare output directory")
}
ctx.Log("event", "created output directory")
dos2unix := 1
if cfg.publicSettings.SkipDos2Unix {
dos2unix = 0
}
// - download files
ctx.Log("files", len(cfg.fileUrls()))
if len(cfg.publicSettings.FileURLs) > 0 {
telemetry("scenario", fmt.Sprintf("public-fileUrls;dos2unix=%d", dos2unix), true, 0*time.Millisecond)
} else if len(cfg.protectedSettings.FileURLs) > 0 {
telemetry("scenario", fmt.Sprintf("protected-fileUrls;dos2unix=%d", dos2unix), true, 0*time.Millisecond)
}
for i, f := range cfg.fileUrls() {
ctx := ctx.With("file", i)
ctx.Log("event", "download start")
if err := downloadAndProcessURL(ctx, f, dir, cfg.StorageAccountName, cfg.StorageAccountKey, cfg.publicSettings.SkipDos2Unix); err != nil {
ctx.Log("event", "download failed", "error", err)
return errors.Wrapf(err, "failed to download file[%d]", i)
}
ctx.Log("event", "download complete", "output", dir)
}
return nil
}