[w3m-dev 03568] Re: preserve timestamp

* etc.c (USE_COOKIE): moved
* file.c (utime.h): include
	(setModtime): added
	(loadGeneralFile): set f.modtime
	(_doFileCopy): setModtime()
	(doFileSave): setModtime()
* ftp.c (getFtpModtime): added
	(openFTP): pass URLFile, set modtime
* html.h (URLFile): add modtime
* proto.h (openFTP): arg URLFile *uf
	(mymktime): always
* url.c (init_stream): initialize modtime
	(openFTPStream): pass URLFile
	(openURL): openFTPStream
From: Takahashi Youichirou <nikuq@hk.airnet.ne.jp>
This commit is contained in:
Fumitoshi UKAI
2002-12-14 15:18:37 +00:00
parent 9963ad03d3
commit 26a8e37fdc
7 changed files with 92 additions and 18 deletions
+19 -1
View File
@@ -1,3 +1,21 @@
2002-12-15 Takahashi Youichirou <nikuq@hk.airnet.ne.jp>
* [w3m-dev 03568] Re: preserve timestamp
* etc.c (USE_COOKIE): moved
* file.c (utime.h): include
(setModtime): added
(loadGeneralFile): set f.modtime
(_doFileCopy): setModtime()
(doFileSave): setModtime()
* ftp.c (getFtpModtime): added
(openFTP): pass URLFile, set modtime
* html.h (URLFile): add modtime
* proto.h (openFTP): arg URLFile *uf
(mymktime): always
* url.c (init_stream): initialize modtime
(openFTPStream): pass URLFile
(openURL): openFTPStream
2002-12-13 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
* [w3m-dev 03567] default keybinding
@@ -5830,4 +5848,4 @@ a * [w3m-dev 03276] compile error on EWS4800
* release-0-2-1
* import w3m-0.2.1
$Id: ChangeLog,v 1.618 2002/12/13 03:02:03 ukai Exp $
$Id: ChangeLog,v 1.619 2002/12/14 15:18:37 ukai Exp $
+2 -2
View File
@@ -1,4 +1,4 @@
/* $Id: etc.c,v 1.42 2002/11/27 16:40:19 ukai Exp $ */
/* $Id: etc.c,v 1.43 2002/12/14 15:18:38 ukai Exp $ */
#include "fm.h"
#include <pwd.h>
#include "myctype.h"
@@ -1518,7 +1518,6 @@ tmpfname(int type, char *ext)
return tmpf;
}
#ifdef USE_COOKIE
static char *monthtbl[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
@@ -1728,6 +1727,7 @@ mymktime(char *timestr)
(hour * 60 * 60) + (min * 60) + sec);
}
#ifdef USE_COOKIE
#ifdef INET6
#include <sys/socket.h>
#endif /* INET6 */
+30 -5
View File
@@ -1,4 +1,4 @@
/* $Id: file.c,v 1.159 2002/12/13 00:09:50 ukai Exp $ */
/* $Id: file.c,v 1.160 2002/12/14 15:18:38 ukai Exp $ */
#include "fm.h"
#include <sys/types.h>
#include "myctype.h"
@@ -11,6 +11,7 @@
#include <time.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <utime.h>
/* foo */
#include "html.h"
@@ -331,6 +332,19 @@ uncompressed_file_type(char *path, char **ext)
return t0;
}
static int setModtime(char *path, time_t modtime)
{
struct utimbuf t;
struct stat st;
if (stat(path, &st) == 0)
t.actime = st.st_atime;
else
t.actime = time(NULL);
t.modtime = modtime;
return utime(path, &t);
}
void
examineFile(char *path, URLFile *uf)
{
@@ -1748,6 +1762,8 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer,
of = &f;
goto load_doc;
}
f.modtime = mymktime(checkHeader(t_buf, "Last-Modified:"));
}
#ifdef USE_NNTP
else if (pu.scheme == SCM_NEWS || pu.scheme == SCM_NNTP) {
@@ -1876,9 +1892,12 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer,
signal(SIGINT, prevtrap);
if (DecodeCTE && IStype(f.stream) != IST_ENCODED)
f.stream = newEncodedStream(f.stream, f.encoding);
if (pu.scheme == SCM_LOCAL)
if (pu.scheme == SCM_LOCAL) {
struct stat st;
if (stat(pu.real_file, &st) == 0)
f.modtime = st.st_mtime;
file = conv_from_system(guess_save_name(NULL, pu.real_file));
else
} else
file = guess_save_name(t_buf, pu.file);
doFileSave(f, file);
if (f.scheme == SCM_FTP)
@@ -7410,6 +7429,8 @@ _doFileCopy(char *tmpf, char *defstr, int download)
QuietMessage = TRUE;
fmInitialized = FALSE;
_MoveFile(tmpf, p);
if (stat(tmpf, &st) == 0)
setModtime(p, st.st_mtime);
unlink(lock);
exit(0);
}
@@ -7443,7 +7464,8 @@ _doFileCopy(char *tmpf, char *defstr, int download)
}
if (_MoveFile(tmpf, p) < 0) {
printf("Can't save to %s\n", p);
}
} else if (stat(tmpf, &st) == 0)
setModtime(p, st.st_mtime);
}
}
@@ -7508,6 +7530,8 @@ doFileSave(URLFile uf, char *defstr)
QuietMessage = TRUE;
fmInitialized = FALSE;
save2tmp(uf, p);
if (uf.modtime != -1)
setModtime(p, uf.modtime);
UFclose(&uf);
unlink(lock);
exit(0);
@@ -7537,7 +7561,8 @@ doFileSave(URLFile uf, char *defstr)
}
if (save2tmp(uf, p) < 0) {
printf("Can't save to %s\n", p);
}
} else if (uf.modtime != -1)
setModtime(p, uf.modtime);
}
}
+31 -2
View File
@@ -1,4 +1,4 @@
/* $Id: ftp.c,v 1.15 2002/11/18 18:26:13 ukai Exp $ */
/* $Id: ftp.c,v 1.16 2002/12/14 15:18:38 ukai Exp $ */
#include <stdio.h>
#include <pwd.h>
#include <Str.h>
@@ -351,6 +351,34 @@ FtpData(FTP ftp, char *cmd, char *arg, char *mode)
return FtpDataBody(ftp, cmd, arg, mode);
}
time_t
getFtpModtime(FTP ftp, char *path)
{
Str tmp;
char *p;
struct tm tm;
time_t t;
memset(&tm, 0, sizeof(struct tm));
tmp = Sprintf("MDTM %s\r\n", path);
fwrite(tmp->ptr, tmp->length, sizeof(char), ftp->wcontrol);
fflush(ftp->wcontrol);
tmp = read_response(ftp);
if (atoi(tmp->ptr) != 213)
return -1;
for (p = tmp->ptr + 4; *p && *p == ' '; p++)
;
if (sscanf(p, "%04d%02d%02d%02d%02d%02d",
&tm.tm_year, &tm.tm_mon, &tm.tm_mday,
&tm.tm_hour, &tm.tm_min, &tm.tm_sec) < 6)
return -1;
tm.tm_year -= 1900;
tm.tm_mon--;
t = mktime(&tm);
t += mktime(localtime(&t)) - mktime(gmtime(&t));
return t;
}
int
FtpClose(FTP ftp)
{
@@ -394,7 +422,7 @@ static int ftp_system(FTP);
#define FTPDIR_FILE 3
FILE *
openFTP(ParsedURL *pu)
openFTP(ParsedURL *pu, URLFile *uf)
{
Str tmp2 = Strnew();
Str tmp3 = Strnew();
@@ -472,6 +500,7 @@ openFTP(ParsedURL *pu)
goto ftp_dir;
/* Get file */
uf->modtime = getFtpModtime(current_ftp, realpathname);
FtpBinary(current_ftp);
if (ftp_pasv(current_ftp) < 0) {
FtpBye(current_ftp);
+2 -1
View File
@@ -1,4 +1,4 @@
/* $Id: html.h,v 1.15 2002/12/09 15:40:37 ukai Exp $ */
/* $Id: html.h,v 1.16 2002/12/14 15:18:38 ukai Exp $ */
#ifndef _HTML_H
#define _HTML_H
#ifdef USE_SSL
@@ -73,6 +73,7 @@ typedef struct {
char *ssl_certificate;
#endif
char *url;
time_t modtime;
} URLFile;
#define CMP_NOCOMPRESS 0
+3 -3
View File
@@ -1,4 +1,4 @@
/* $Id: proto.h,v 1.71 2002/12/13 02:19:01 ukai Exp $ */
/* $Id: proto.h,v 1.72 2002/12/14 15:18:38 ukai Exp $ */
/*
* This file was automatically generated by version 1.7 of cextract.
* Manual editing not recommended.
@@ -504,7 +504,7 @@ extern Str unquote_mailcap(char *qstr, char *type, char *name, char *attr,
extern char *guessContentType(char *filename);
extern TextList *make_domain_list(char *domain_list);
extern int check_no_proxy(char *domain);
extern FILE *openFTP(ParsedURL *pu);
extern FILE *openFTP(ParsedURL *pu, URLFile *uf);
extern Str readFTPDir(ParsedURL *pu);
extern void closeFTP(FILE * f);
extern int Ftpfclose(FILE * f);
@@ -588,8 +588,8 @@ extern Str myEditor(char *cmd, char *file, int line);
extern char *file_to_url(char *file);
extern char *expandName(char *name);
extern Str tmpfname(int type, char *ext);
#ifdef USE_COOKIE
extern time_t mymktime(char *timestr);
#ifdef USE_COOKIE
extern char *FQDN(char *host);
extern Str find_cookie(ParsedURL *pu);
extern int add_cookie(ParsedURL *pu, Str name, Str value, time_t expires,
+5 -4
View File
@@ -1,4 +1,4 @@
/* $Id: url.c,v 1.58 2002/11/18 17:32:33 ukai Exp $ */
/* $Id: url.c,v 1.59 2002/12/14 15:18:39 ukai Exp $ */
#include "fm.h"
#include <sys/types.h>
#include <sys/socket.h>
@@ -1412,12 +1412,13 @@ init_stream(URLFile *uf, int scheme, InputStream stream)
uf->compression = 0;
uf->guess_type = NULL;
uf->ext = NULL;
uf->modtime = -1;
}
static InputStream
openFTPStream(ParsedURL *pu)
openFTPStream(ParsedURL *pu, URLFile *uf)
{
return newFileStream(openFTP(pu), closeFTP);
return newFileStream(openFTP(pu, uf), closeFTP);
}
URLFile
@@ -1587,7 +1588,7 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current,
write(sock, tmp->ptr, tmp->length);
}
else {
uf.stream = openFTPStream(pu);
uf.stream = openFTPStream(pu, &uf);
uf.scheme = pu->scheme;
return uf;
}