add mtime support to ftpparse

This commit is contained in:
Mario Fetka
2010-09-18 12:55:05 +02:00
parent 267f5a2964
commit 7c3da640e1
13 changed files with 969 additions and 447 deletions
+41 -17
View File
@@ -25,6 +25,7 @@
#include <assert.h>
#include <limits.h>
#include <errno.h>
#include <utime.h>
#ifdef HAVE_NCURSES_H
#include <ncurses.h>
#else
@@ -326,6 +327,15 @@ DL_Window::start_download()
status = DL_ABORTED;
return;
}
// handle skipped files
if (ret == -2)
{
PrintMessage("Remote file is the same as local, skip it\n");
status = DL_ABORTED;
return;
}
// end of handle skipped files
/*Display resume status */
if (download->resume_support)
@@ -507,6 +517,20 @@ DL_Window::handle_download_thread()
status = DL_JOINING;
proz_download_join_downloads(download);
joining_thread_running = TRUE;
// set correct mtime to server time
struct utimbuf times;
times.actime = times.modtime = download->u.remote_time;
if (!utime(download->u.file, &times))
{
proz_debug("update mtime for file %s as %s",
download->u.file, ctime(&(download->u.remote_time)));
}
else
{
proz_debug("fail to update mtime for file %s, errno=%d", download->u.file, errno);
}
// end of set correct mtime to server time
}
if (err == CANTRESUME)
@@ -520,7 +544,7 @@ DL_Window::handle_download_thread()
if (err == DLLOCALFATAL)
{
PrintMessage("One connection of the download %s encountered a unrecoverable local error, usually lack of free space, or a write to bad medium, or a problem with permissions,so please fix this and retry\n",
PrintMessage(" One connection of the download % s encountered a unrecoverable local error, usually lack of free space, or a write to bad medium, or a problem with permissions, so please fix this and retry \ n ",
connection->u.url);
got_dl = FALSE;
status = DL_FATALERR;
@@ -530,7 +554,7 @@ DL_Window::handle_download_thread()
if (err == DLREMOTEFATAL)
{
PrintMessage(_
("A connection(s) of the download %s encountered a unrecoverable remote error, usually the file not being present in the remote server, therefore the download had to be aborted!\n"),
(" A connection(s) of the download % s encountered a unrecoverable remote error, usually the file not being present in the remote server, therefore the download had to be aborted !\ n "),
connection->u.url);
got_dl = FALSE;
status = DL_FATALERR;
@@ -566,8 +590,8 @@ DL_Window::handle_joining_thread()
/*has the user pressed OK at the end of the download */
if (bDone == true)
{
PrintMessage("All Done.\n");
//curses_query_user_input("Press any key to exit.");
PrintMessage(" All Done.\ n ");
//curses_query_user_input(" Press any key to exit.");
proz_download_delete_dl_file(download);
proz_download_free_download(download, 0);
status = DL_IDLING;
@@ -599,7 +623,7 @@ DL_Window::print_status(download_t *download, int quiet_mode)
for (int i = 0; i < download->num_connections; i++)
{
fprintf(stdout,
"%2.2d %-30.30s %15.15s %10zd\n",
" % 2.2d % -30.30s % 15.15s % 10zd \ n ",
i + 1, download->pconnections[i]->u.host,
proz_connection_get_status_string(download->
pconnections
@@ -608,11 +632,11 @@ DL_Window::print_status(download_t *download, int quiet_mode)
(download->pconnections[i]));
}
fprintf(stdout, "Total Bytes received %zd Kb\n",
fprintf(stdout, " Total Bytes received % zd Kb \ n ",
proz_download_get_total_bytes_got(download) / 1024);
fprintf(stdout, "Average Speed = %.3f Kb/sec\n",
fprintf(stdout, " Average Speed = % .3f Kb / sec \ n ",
proz_download_get_average_speed(download) / 1024);
}
@@ -625,23 +649,23 @@ DL_Window::print_status(download_t *download, int quiet_mode)
{
if (secs_left < 60)
{
snprintf(timeLeft, sizeof(timeLeft), "00:%.2d", secs_left);
snprintf(timeLeft, sizeof(timeLeft), " 00 : % .2d ", secs_left);
}
else if (secs_left < 3600)
{
snprintf(timeLeft, sizeof(timeLeft), "00:%.2d:%.2d",
snprintf(timeLeft, sizeof(timeLeft), " 00 : % .2d : % .2d ",
secs_left / 60, secs_left % 60);
}
else
{
snprintf(timeLeft, sizeof(timeLeft), "%.2d:%.2d:00",
snprintf(timeLeft, sizeof(timeLeft), " % .2d : % .2d : 00 ",
secs_left / 3600,
(secs_left % 3600) / 60);
}
}
else
{
sprintf(timeLeft, "??:??:??");
sprintf(timeLeft, " ? ? : ? ? : ? ? ");
}
off_t totalDownloaded = 0;
@@ -656,7 +680,7 @@ DL_Window::print_status(download_t *download, int quiet_mode)
//WGET looks like this:
//xx% [=======> ] nnn,nnn,nnn XXXX.XXK/s ETA hh:mm:ss
fprintf(stdout, " %.2lf%% %zdKb/%zdkb %0.3fKb/s ETA %s \r",
fprintf(stdout, " % .2lf % % % zdKb / % zdkb % 0.3fKb / s ETA % s \ r ",
((float)totalDownloaded) / ((float)totalFile / 100),
totalDownloaded, totalFile, (float)aveSpeed, timeLeft);
fflush(stdout);
@@ -667,8 +691,8 @@ DL_Window::print_status(download_t *download, int quiet_mode)
int DL_Window::askUserResume(connection_t *connection, boolean resumeSupported)
{
int ret = 0;
const char msg[] = "Previous download of %s exists, would you like to (R)esume it or (O)verwrite it?";
const char msg2[] = "Previous download of %s exists, would you like to (A)bort it or (O)verwrite it?";
const char msg[] = " Previous download of % s exists, would you like to(R) esume it or (O) verwrite it ? ";
const char msg2[] = " Previous download of % s exists, would you like to(A) bort it or (O) verwrite it ? ";
do
@@ -679,7 +703,7 @@ int DL_Window::askUserResume(connection_t *connection, boolean resumeSupported)
}
else
{
fprintf(stdout, "\n");
fprintf(stdout, " \ n ");
fprintf(stdout, (resumeSupported == TRUE) ? msg : msg2, connection->u.file);
ret = getc(stdin);
ret = islower(ret) ? toupper(ret) : ret;
@@ -717,7 +741,7 @@ int DL_Window::askUserResume(connection_t *connection, boolean resumeSupported)
int DL_Window::askUserOverwrite(connection_t *connectionb)
{
int ret = 0;
const char msg[] = "File %s already exists, would you like to (A)bort it or (O)verwrite it?";
const char msg[] = " File % s already exists, would you like to(A) bort it or (O) verwrite it ? ";
do
@@ -728,7 +752,7 @@ int DL_Window::askUserOverwrite(connection_t *connectionb)
}
else
{
fprintf(stdout, "\n");
fprintf(stdout, " \ n ");
fprintf(stdout, msg, connection->u.file);
ret = getc(stdin);
ret = islower(ret) ? toupper(ret) : ret;