static gboolean up_sync_file(GFile* root, GFile* file, const gchar* remote_path) { GError *local_err = NULL; mega_node* node = mega_session_stat(s, remote_path); if (node) { g_printerr("ERROR: File already exists at %s\n", remote_path); return FALSE; } g_print("F %s\n", remote_path); if (!opt_dryrun) { if (!mega_session_put(s, remote_path, g_file_get_path(file), &local_err)) { if (!opt_noprogress) g_print("\r" ESC_CLREOL); g_printerr("ERROR: Upload failed for %s: %s\n", remote_path, local_err->message); g_clear_error(&local_err); return FALSE; } if (!opt_noprogress) g_print("\r" ESC_CLREOL); } return TRUE; }
int main(int ac, char* av[]) { GError *local_err = NULL; mega_session* s; tool_init(&ac, &av, "- upload files to mega.co.nz", entries); if (ac < 2) { g_printerr("ERROR: No files specified for upload!\n"); tool_fini(NULL); return 1; } s = tool_start_session(); if (!s) return 1; mega_session_watch_status(s, status_callback, NULL); gint i; for (i = 1; i < ac; i++) { cur_file = g_path_get_basename(av[i]); // perform download if (!mega_session_put(s, opt_path, av[i], &local_err)) { if (!opt_noprogress) g_print("\r" ESC_CLREOL "\n"); g_printerr("ERROR: Upload failed for '%s': %s\n", av[i], local_err->message); g_clear_error(&local_err); } else { if (!opt_noprogress) g_print("\r" ESC_CLREOL "Uploaded %s\n", cur_file); } g_free(cur_file); } mega_session_save(s, NULL); tool_fini(s); return 0; }