// A simple app to reveal a crasher bug in gvfs when downloading multiple files from HTTP
//
// Build with: valac-0.18 --pkg gio-2.0 multi-downloads.vala
//
// Run as: ./multi-downloads URI1 URI2

private async void download (string uri) {
    var remote_file = File.new_for_uri (uri);
    var local_path = remote_file.get_basename ();
    var local_file = File.new_for_path (local_path);
    try {
        print ("Downloading '%s' to '%s'...\n", uri, local_path);
        yield remote_file.copy_async (local_file, FileCopyFlags.NONE);
        print ("Downloaded '%s' to '%s'.\n", uri, local_path);
    } catch (GLib.Error error) {
        warning ("Error loading logo file '%s': %s", uri, error.message);
    }
}

public static int main (string[] args) {
    foreach (var arg in args[1:args.length])
        download.begin (arg);

    var main_loop = new GLib.MainLoop ();
    main_loop.run ();

    return 0;
}
