aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFumitoshi UKAI <ukai@debian.or.jp>2002-12-14 15:18:37 +0000
committerFumitoshi UKAI <ukai@debian.or.jp>2002-12-14 15:18:37 +0000
commit26a8e37fdcab433c8e623b29fb35c0907b2a05de (patch)
tree9228e612a67095337200051b47b0f14c99485ac8
parent[w3m-dev 03567] default keybinding (diff)
downloadw3m-26a8e37fdcab433c8e623b29fb35c0907b2a05de.tar.gz
w3m-26a8e37fdcab433c8e623b29fb35c0907b2a05de.zip
[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>
Diffstat (limited to '')
-rw-r--r--ChangeLog20
-rw-r--r--etc.c4
-rw-r--r--file.c35
-rw-r--r--ftp.c33
-rw-r--r--html.h3
-rw-r--r--proto.h6
-rw-r--r--url.c9
7 files changed, 92 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index 68ce5f9..3e9a563 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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 $
diff --git a/etc.c b/etc.c
index 514ef6e..616bdf2 100644
--- a/etc.c
+++ b/etc.c
@@ -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 */
diff --git a/file.c b/file.c
index be97981..29d994b 100644
--- a/file.c
+++ b/file.c
@@ -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);
}
}
diff --git a/ftp.c b/ftp.c
index 0a8de3f..47c7fd0 100644
--- a/ftp.c
+++ b/ftp.c
@@ -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);
diff --git a/html.h b/html.h
index afd0e9c..5683dcc 100644
--- a/html.h
+++ b/html.h
@@ -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
diff --git a/proto.h b/proto.h
index 94c9b0e..eca5dc7 100644
--- a/proto.h
+++ b/proto.h
@@ -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,
diff --git a/url.c b/url.c
index 03e4c2f..fd328c3 100644
--- a/url.c
+++ b/url.c
@@ -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;
}