📄 gftpui.c
字号:
gftp_lookup_request_option (fromreq, "append_transfers", &append_transfers); gftp_lookup_request_option (fromreq, "one_transfer", &one_transfer); tdata = NULL; if (append_transfers && one_transfer && !show_dialog) { if (g_thread_supported ()) g_static_mutex_lock (&gftpui_common_transfer_mutex); for (templist = gftp_file_transfers; templist != NULL; templist = templist->next) { tdata = templist->data; if (g_thread_supported ()) g_static_mutex_lock (&tdata->structmutex); if (!compare_request (tdata->fromreq, fromreq, 0) || !compare_request (tdata->toreq, toreq, 0) || tdata->curfle == NULL) { if (g_thread_supported ()) g_static_mutex_unlock (&tdata->structmutex); continue; } tdata->files = g_list_concat (tdata->files, files); for (curfle = files; curfle != NULL; curfle = curfle->next) { tempfle = curfle->data; if (S_ISDIR (tempfle->st_mode)) tdata->numdirs++; else tdata->numfiles++; if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) tdata->total_bytes += tempfle->size; gftpui_add_file_to_transfer (tdata, curfle); } if (g_thread_supported ()) g_static_mutex_unlock (&tdata->structmutex); break; } if (g_thread_supported ()) g_static_mutex_unlock (&gftpui_common_transfer_mutex); } else templist = NULL; if (templist == NULL) { tdata = gftp_tdata_new (); tdata->fromreq = gftp_copy_request (fromreq); tdata->toreq = gftp_copy_request (toreq); tdata->fromwdata = fromuidata; tdata->towdata = touidata; if (!show_dialog) tdata->show = tdata->ready = 1; tdata->files = files; for (curfle = files; curfle != NULL; curfle = curfle->next) { tempfle = curfle->data; if (S_ISDIR (tempfle->st_mode)) tdata->numdirs++; else tdata->numfiles++; if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP) tdata->total_bytes += tempfle->size; } if (g_thread_supported ()) g_static_mutex_lock (&gftpui_common_transfer_mutex); gftp_file_transfers = g_list_append (gftp_file_transfers, tdata); if (g_thread_supported ()) g_static_mutex_unlock (&gftpui_common_transfer_mutex); if (show_dialog) gftpui_ask_transfer (tdata); } gftpui_start_transfer (tdata); return (tdata);}static void_gftpui_common_setup_fds (gftp_transfer * tdata, gftp_file * curfle, int *fromfd, int *tofd){ *tofd = -1; *fromfd = -1; if (curfle->is_fd) { if (tdata->toreq->protonum == GFTP_LOCAL_NUM) *tofd = curfle->fd; else if (tdata->fromreq->protonum == GFTP_LOCAL_NUM) *fromfd = curfle->fd; }}static void_gftpui_common_done_with_fds (gftp_transfer * tdata, gftp_file * curfle){ if (curfle->is_fd) { if (tdata->toreq->protonum == GFTP_LOCAL_NUM) tdata->toreq->datafd = -1; else tdata->fromreq->datafd = -1; }}intgftpui_common_transfer_files (gftp_transfer * tdata){ intptr_t preserve_permissions, preserve_time, trans_blksize; struct timeval updatetime; ssize_t num_read, ret; gftp_file * curfle; int tofd, fromfd; char *buf; gftp_lookup_request_option (tdata->fromreq, "trans_blksize", &trans_blksize); buf = g_malloc (trans_blksize); tdata->curfle = tdata->files; gettimeofday (&tdata->starttime, NULL); memcpy (&tdata->lasttime, &tdata->starttime, sizeof (tdata->lasttime)); while (tdata->curfle != NULL) { num_read = -1; if (g_thread_supported ()) g_static_mutex_lock (&tdata->structmutex); curfle = tdata->curfle->data; tdata->current_file_number++; if (g_thread_supported ()) g_static_mutex_unlock (&tdata->structmutex); if (curfle->transfer_action == GFTP_TRANS_ACTION_SKIP) { if (g_thread_supported ()) g_static_mutex_lock (&tdata->structmutex); tdata->next_file = 1; tdata->curfle = tdata->curfle->next; if (g_thread_supported ()) g_static_mutex_unlock (&tdata->structmutex); continue; } tdata->tot_file_trans = -1; if (gftp_connect (tdata->fromreq) == 0 && gftp_connect (tdata->toreq) == 0) { if (S_ISDIR (curfle->st_mode)) { if (tdata->toreq->mkdir != NULL) { tdata->toreq->mkdir (tdata->toreq, curfle->destfile); if (!GFTP_IS_CONNECTED (tdata->toreq)) break; } if (g_thread_supported ()) g_static_mutex_lock (&tdata->structmutex); tdata->next_file = 1; tdata->curfle = tdata->curfle->next; if (g_thread_supported ()) g_static_mutex_unlock (&tdata->structmutex); continue; } _gftpui_common_setup_fds (tdata, curfle, &fromfd, &tofd); if (curfle->size == 0) { curfle->size = gftp_get_file_size (tdata->fromreq, curfle->file); tdata->total_bytes += curfle->size; } if (GFTP_IS_CONNECTED (tdata->fromreq) && GFTP_IS_CONNECTED (tdata->toreq)) { tdata->tot_file_trans = gftp_transfer_file (tdata->fromreq, curfle->file, fromfd, curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? curfle->startsize : 0, tdata->toreq, curfle->destfile, tofd, curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? curfle->startsize : 0); } } if (!GFTP_IS_CONNECTED (tdata->fromreq) || !GFTP_IS_CONNECTED (tdata->toreq)) { tdata->fromreq->logging_function (gftp_logging_error, tdata->fromreq, _("Error: Remote site disconnected after trying to transfer file\n")); } else if (tdata->tot_file_trans < 0) { if (g_thread_supported ()) g_static_mutex_lock (&tdata->structmutex); curfle->transfer_action = GFTP_TRANS_ACTION_SKIP; tdata->next_file = 1; tdata->curfle = tdata->curfle->next; if (g_thread_supported ()) g_static_mutex_unlock (&tdata->structmutex); continue; } else { if (g_thread_supported ()) g_static_mutex_lock (&tdata->structmutex); tdata->curtrans = 0; tdata->curresumed = curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? curfle->startsize : 0; tdata->resumed_bytes += tdata->curresumed; if (g_thread_supported ()) g_static_mutex_unlock (&tdata->structmutex); memset (&updatetime, 0, sizeof (updatetime)); gftpui_start_current_file_in_transfer (tdata); while (!tdata->cancel && (num_read = gftp_get_next_file_chunk (tdata->fromreq, buf, trans_blksize)) > 0) { gftp_calc_kbs (tdata, num_read); if (tdata->lasttime.tv_sec - updatetime.tv_sec >= 1 || tdata->curtrans >= tdata->tot_file_trans) { gftpui_update_current_file_in_transfer (tdata); memcpy (&updatetime, &tdata->lasttime, sizeof (updatetime)); } if ((ret = gftp_put_next_file_chunk (tdata->toreq, buf, num_read)) < 0) { num_read = (int) ret; break; } } if (num_read == GFTP_ENOTRANS) num_read = 0; gftpui_finish_current_file_in_transfer (tdata); } if (tdata->cancel) { if (gftp_abort_transfer (tdata->fromreq) != 0) gftp_disconnect (tdata->fromreq); if (gftp_abort_transfer (tdata->toreq) != 0) gftp_disconnect (tdata->toreq); } else if (num_read < 0) { tdata->fromreq->logging_function (gftp_logging_error, tdata->fromreq, _("Could not download %s from %s\n"), curfle->file, tdata->fromreq->hostname); if (gftp_get_transfer_status (tdata, num_read) == GFTP_ERETRYABLE) continue; break; } else { _gftpui_common_done_with_fds (tdata, curfle); if (gftp_end_transfer (tdata->fromreq) != 0) { if (gftp_get_transfer_status (tdata, -1) == GFTP_ERETRYABLE) continue; break; } if (gftp_end_transfer (tdata->toreq) == 0) { tdata->fromreq->logging_function (gftp_logging_misc, tdata->fromreq, _("Successfully transferred %s at %.2f KB/s\n"), curfle->file, tdata->kbs); } else { tdata->fromreq->logging_function (gftp_logging_error, tdata->fromreq, _("There was an error transfering the file %s"), curfle->file); } } gftp_lookup_request_option (tdata->fromreq, "preserve_permissions", &preserve_permissions); gftp_lookup_request_option (tdata->fromreq, "preserve_time", &preserve_time); if (!curfle->is_fd) { if (preserve_permissions && curfle->st_mode != 0) gftp_chmod (tdata->toreq, curfle->destfile, curfle->st_mode & (S_IRWXU | S_IRWXG | S_IRWXO)); if (preserve_time && curfle->datetime != 0) gftp_set_file_time (tdata->toreq, curfle->destfile, curfle->datetime); } if (g_thread_supported ()) g_static_mutex_lock (&tdata->structmutex); tdata->curtrans = 0; tdata->next_file = 1; curfle->transfer_done = 1; tdata->curfle = tdata->curfle->next; if (g_thread_supported ()) g_static_mutex_unlock (&tdata->structmutex); if (tdata->cancel && !tdata->skip_file) break; tdata->cancel = 0; tdata->fromreq->cancel = 0; tdata->toreq->cancel = 0; } tdata->done = 1; g_free (buf); return (1);}voidgftpui_protocol_update_timeout (gftp_request * request){ intptr_t network_timeout; gftp_lookup_request_option (request, "network_timeout", &network_timeout); if (network_timeout > 0) alarm (network_timeout);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -