You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Matt Kraai <kr...@alumni.cmu.edu> on 2003/01/25 00:53:48 UTC

[PATCH] create apr_file_mtime_set

Howdy,

Subversion needs to change the files' modification times.  The
appended patch adds apr_file_mtime_set, which does so.  It also
adds apr_time_ansi_get, which is used to convert an apr_time_t to
a time_t.

It only implements them on UNIX.  If this isn't acceptable, please
let me know what I need to do.

Matt

diff -ur apr.orig/configure.in apr/configure.in
--- apr.orig/configure.in	2003-01-06 16:10:03.000000000 -0800
+++ apr/configure.in	2003-01-24 15:37:29.000000000 -0800
@@ -935,6 +935,7 @@
     tpfio.h		\
     unistd.h		\
     unix.h		\
+    utime.h		\
     arpa/inet.h		\
     kernel/OS.h		\
     net/errno.h		\
@@ -1005,6 +1006,7 @@
 AC_SUBST(sys_unh)
 AC_SUBST(timeh)
 AC_SUBST(unistdh)
+AC_SUBST(utimeh)
 AC_SUBST(signalh)
 AC_SUBST(sys_waith)
 AC_SUBST(pthreadh)
diff -ur apr.orig/file_io/unix/filestat.c apr/file_io/unix/filestat.c
--- apr.orig/file_io/unix/filestat.c	2003-01-06 21:28:47.000000000 -0800
+++ apr/file_io/unix/filestat.c	2003-01-24 15:39:31.000000000 -0800
@@ -202,6 +202,26 @@
     return apr_file_perms_set(fname, finfo.protection);
 }
 
+APR_DECLARE(apr_status_t) apr_file_mtime_set(const char *fname,
+					     apr_time_t mtime,
+					     apr_pool_t *pool)
+{
+    apr_status_t status;
+    apr_finfo_t finfo;
+    struct utimbuf ut;
+
+    status = apr_stat(&finfo, fname, APR_FINFO_ATIME, pool);
+    if (!APR_STATUS_IS_SUCCESS(status))
+        return status;
+
+    apr_time_ansi_get(&ut.actime, finfo.atime);
+    apr_time_ansi_get(&ut.modtime, mtime);
+
+    if (utime(fname, &ut) == -1)
+	return errno;
+    return APR_SUCCESS;
+}
+
 APR_DECLARE(apr_status_t) apr_stat(apr_finfo_t *finfo, 
                                    const char *fname, 
                                    apr_int32_t wanted, apr_pool_t *pool)
diff -ur apr.orig/include/apr.h.in apr/include/apr.h.in
--- apr.orig/include/apr.h.in	2003-01-22 15:54:18.000000000 -0800
+++ apr/include/apr.h.in	2003-01-24 15:36:14.000000000 -0800
@@ -66,6 +66,7 @@
 #define APR_HAVE_SYS_WAIT_H      @sys_waith@
 #define APR_HAVE_TIME_H          @timeh@
 #define APR_HAVE_UNISTD_H        @unistdh@
+#define APR_HAVE_UTIME_H         @utimeh@
 
 #define APR_HAVE_SHMEM_MMAP_TMP     @havemmaptmp@
 #define APR_HAVE_SHMEM_MMAP_SHM     @havemmapshm@
diff -ur apr.orig/include/apr_file_io.h apr/include/apr_file_io.h
--- apr.orig/include/apr_file_io.h	2002-12-31 21:22:29.000000000 -0800
+++ apr/include/apr_file_io.h	2003-01-24 14:59:26.000000000 -0800
@@ -628,6 +628,18 @@
                                              apr_pool_t *cont);
 
 /**
+ * Set the mtime of the specified file.
+ * @param fname The full path to the file (using / on all systems)
+ * @param mtime The mtime to apply to the file.
+ * @param pool The pool to use.
+ * @warning Platforms which do not implement this feature will return
+ *      APR_ENOTIMPL.
+ */
+APR_DECLARE(apr_status_t) apr_file_mtime_set(const char *fname,
+					     apr_time_t mtime,
+					     apr_pool_t *pool);
+
+/**
  * Create a new directory on the file system.
  * @param path the path for the directory to be created.  (use / on all systems)
  * @param perm Permissions for the new direcoty.
diff -ur apr.orig/include/apr_time.h apr/include/apr_time.h
--- apr.orig/include/apr_time.h	2002-12-31 21:22:29.000000000 -0800
+++ apr/include/apr_time.h	2003-01-24 15:10:24.000000000 -0800
@@ -161,6 +161,14 @@
                                                     time_t input);
 
 /**
+ * convert an apr_time_t to an ansi time_t
+ * @param result the resulting time_t
+ * @param input the apr_time_t to convert
+ */
+APR_DECLARE(apr_status_t) apr_time_ansi_get(time_t *result,
+					    apr_time_t input);
+
+/**
  * convert a time to its human readable components using an offset
  * from GMT
  * @param result the exploded time
diff -ur apr.orig/include/arch/unix/apr_arch_file_io.h apr/include/arch/unix/apr_arch_file_io.h
--- apr.orig/include/arch/unix/apr_arch_file_io.h	2003-01-06 16:52:54.000000000 -0800
+++ apr/include/arch/unix/apr_arch_file_io.h	2003-01-24 15:13:08.000000000 -0800
@@ -102,6 +102,9 @@
 #if APR_HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
+#if APR_HAVE_UTIME_H
+#include <utime.h>
+#endif
 #ifdef BEOS
 #include <kernel/OS.h>
 #endif
diff -ur apr.orig/time/unix/time.c apr/time/unix/time.c
--- apr.orig/time/unix/time.c	2003-01-06 16:10:20.000000000 -0800
+++ apr/time/unix/time.c	2003-01-24 15:11:47.000000000 -0800
@@ -107,6 +107,13 @@
     return APR_SUCCESS;
 }
 
+APR_DECLARE(apr_status_t) apr_time_ansi_get(time_t *result,
+					    apr_time_t input)
+{
+    *result = (time_t)(input / APR_USEC_PER_SEC);
+    return APR_SUCCESS;
+}
+
 /* NB NB NB NB This returns GMT!!!!!!!!!! */
 APR_DECLARE(apr_time_t) apr_time_now(void)
 {

Re: [PATCH] create apr_file_mtime_set

Posted by Matt Kraai <kr...@alumni.cmu.edu>.
On Sat, Jan 25, 2003 at 08:11:17AM -0800, Justin Erenkrantz wrote:
> --On Friday, January 24, 2003 3:53 PM -0800 Matt Kraai 
> <kr...@alumni.cmu.edu> wrote:
> 
> >Subversion needs to change the files' modification times.  The
> >appended patch adds apr_file_mtime_set, which does so.  It also
> >adds apr_time_ansi_get, which is used to convert an apr_time_t to
> >a time_t.
> 
> Most of the manpages I read say that we should use utimes() not 
> utime().  It seems it'd be good to get away from using the utimbuf 
> structure if at all possible.  I'm not sure about the general 
> availability of utimes() though (autoconf test?).

I switched to utimes, though I didn't add an autoconf test.

> I would think it would be best to have apr_time_ansi_get as a macro 
> rather than a function.  (And that macro should just use the 
> apr_time_as_sec macro with an appropriate cast.)

I avoided apr_time_ansi_get altogether.

> I would also suggest reviewing the style guidelines.  You have tabs 
> and no braces around if statements.  -- justin

Fixed.

How about the following patch?

Index: file_io/unix/filestat.c
===================================================================
RCS file: /home/cvspublic/apr/file_io/unix/filestat.c,v
retrieving revision 1.65
diff -u -r1.65 filestat.c
--- file_io/unix/filestat.c	6 Mar 2003 09:21:24 -0000	1.65
+++ file_io/unix/filestat.c	4 Apr 2003 03:58:25 -0000
@@ -208,6 +208,30 @@
     return apr_file_perms_set(fname, finfo.protection);
 }
 
+APR_DECLARE(apr_status_t) apr_file_mtime_set(const char *fname,
+                                             apr_time_t mtime,
+                                             apr_pool_t *pool)
+{
+    apr_status_t status;
+    apr_finfo_t finfo;
+    struct timeval tvp[2];
+
+    status = apr_stat(&finfo, fname, APR_FINFO_ATIME, pool);
+    if (!APR_STATUS_IS_SUCCESS(status)) {
+        return status;
+    }
+
+    tvp[0].tv_sec = apr_time_sec(finfo.atime);
+    tvp[0].tv_usec = apr_time_usec(finfo.atime);
+    tvp[1].tv_sec = apr_time_sec(mtime);
+    tvp[1].tv_usec = apr_time_usec(mtime);
+
+    if (utimes(fname, tvp) == -1) {
+        return errno;
+    }
+    return APR_SUCCESS;
+}
+
 APR_DECLARE(apr_status_t) apr_stat(apr_finfo_t *finfo, 
                                    const char *fname, 
                                    apr_int32_t wanted, apr_pool_t *pool)
Index: include/apr_file_io.h
===================================================================
RCS file: /home/cvspublic/apr/include/apr_file_io.h,v
retrieving revision 1.138
diff -u -r1.138 apr_file_io.h
--- include/apr_file_io.h	3 Apr 2003 23:20:05 -0000	1.138
+++ include/apr_file_io.h	4 Apr 2003 03:58:27 -0000
@@ -658,6 +658,18 @@
                                              apr_pool_t *cont);
 
 /**
+ * Set the mtime of the specified file.
+ * @param fname The full path to the file (using / on all systems)
+ * @param mtime The mtime to apply to the file.
+ * @param pool The pool to use.
+ * @warning Platforms which do not implement this feature will return
+ *      APR_ENOTIMPL.
+ */
+APR_DECLARE(apr_status_t) apr_file_mtime_set(const char *fname,
+                                             apr_time_t mtime,
+                                             apr_pool_t *pool);
+
+/**
  * Create a new directory on the file system.
  * @param path the path for the directory to be created.  (use / on all systems)
  * @param perm Permissions for the new direcoty.

Matt
-- 
It's most certainly GNU/Linux, not Linux.  Read more at
http://www.gnu.org/gnu/why-gnu-linux.html.

Re: [PATCH] create apr_file_mtime_set

Posted by Justin Erenkrantz <je...@apache.org>.
--On Friday, January 24, 2003 3:53 PM -0800 Matt Kraai 
<kr...@alumni.cmu.edu> wrote:

> Subversion needs to change the files' modification times.  The
> appended patch adds apr_file_mtime_set, which does so.  It also
> adds apr_time_ansi_get, which is used to convert an apr_time_t to
> a time_t.

Most of the manpages I read say that we should use utimes() not 
utime().  It seems it'd be good to get away from using the utimbuf 
structure if at all possible.  I'm not sure about the general 
availability of utimes() though (autoconf test?).

I would think it would be best to have apr_time_ansi_get as a macro 
rather than a function.  (And that macro should just use the 
apr_time_as_sec macro with an appropriate cast.)

I would also suggest reviewing the style guidelines.  You have tabs 
and no braces around if statements.  -- justin