apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From suss...@apache.org
Subject cvs commit: apr/test testfileinfo.c
Date Mon, 07 Jul 2003 22:44:11 GMT
sussman     2003/07/07 15:44:11

  Modified:    file_io/unix filestat.c
               file_io/win32 filestat.c open.c
               include  apr_file_io.h
               include/arch/win32 apr_arch_file_io.h
               test     testfileinfo.c
  Log:
  New apr_file_mtime_set() API, implemented in unix and win32.
  Patches from Branko Cibej (brane) and Matt Kraai <kraai@alumni.cmu.edu>.
  
  * include/apr_file_io.h (apr_file_mtime_set):  declare.
  
  * include/arch/win32/apr_arch_file_io.h:  expand apr_file_open
    internal flags;  add new APR_WRITEATTRS value.
  
  * file_io/win32/open.c (apr_file_open): honor APR_WRITEATTRS flag.
  
  * file_io/win32/filestat.c (apr_file_mtime_set):  implement in win32.
  
  * file_io/unix/filestat.c (apr_file_mtime_set):  implement in unix.
  
  * test/testfileinfo.c (test_mtime_set):  new API test.
  
  Revision  Changes    Path
  1.67      +26 -0     apr/file_io/unix/filestat.c
  
  Index: filestat.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/unix/filestat.c,v
  retrieving revision 1.66
  retrieving revision 1.67
  diff -u -r1.66 -r1.67
  --- filestat.c	24 May 2003 10:30:39 -0000	1.66
  +++ filestat.c	7 Jul 2003 22:44:10 -0000	1.67
  @@ -213,6 +213,32 @@
       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)
  
  
  
  1.81      +34 -0     apr/file_io/win32/filestat.c
  
  Index: filestat.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/win32/filestat.c,v
  retrieving revision 1.80
  retrieving revision 1.81
  diff -u -r1.80 -r1.81
  --- filestat.c	24 May 2003 10:30:39 -0000	1.80
  +++ filestat.c	7 Jul 2003 22:44:10 -0000	1.81
  @@ -762,3 +762,37 @@
   
       return APR_SUCCESS;
   }
  +
  +
  +APR_DECLARE(apr_status_t) apr_file_mtime_set(const char *fname,
  +                                             apr_time_t mtime,
  +                                             apr_pool_t *pool)
  +{
  +    apr_file_t *thefile;
  +    apr_status_t rv;
  +
  +    rv = apr_file_open(&thefile, fname,
  +                       APR_READ | APR_WRITEATTRS,
  +                       APR_OS_DEFAULT, pool);
  +    if (!rv)
  +    {
  +        FILETIME file_ctime;
  +        FILETIME file_atime;
  +        FILETIME file_mtime;
  +
  +        if (!GetFileTime(thefile->filehand,
  +                         &file_ctime, &file_atime, &file_mtime))
  +            rv = apr_get_os_error();
  +        else
  +        {
  +            AprTimeToFileTime(&file_mtime, mtime);
  +            if (!SetFileTime(thefile->filehand,
  +                             &file_ctime, &file_atime, &file_mtime))
  +                rv = apr_get_os_error();
  +        }
  +
  +        apr_file_close(thefile);
  +    }
  +
  +    return rv;
  +}
  
  
  
  1.118     +4 -1      apr/file_io/win32/open.c
  
  Index: open.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/win32/open.c,v
  retrieving revision 1.117
  retrieving revision 1.118
  diff -u -r1.117 -r1.118
  --- open.c	7 Jan 2003 00:52:54 -0000	1.117
  +++ open.c	7 Jul 2003 22:44:10 -0000	1.118
  @@ -309,7 +309,10 @@
       if (flag & APR_WRITE) {
           oflags |= GENERIC_WRITE;
       }
  -    
  +    if (flag & APR_WRITEATTRS) {
  +        oflags |= FILE_WRITE_ATTRIBUTES;
  +    }
  +
       if (apr_os_level >= APR_WIN_NT) 
           sharemode |= FILE_SHARE_DELETE;
   
  
  
  
  1.142     +12 -0     apr/include/apr_file_io.h
  
  Index: apr_file_io.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_file_io.h,v
  retrieving revision 1.141
  retrieving revision 1.142
  diff -u -r1.141 -r1.142
  --- apr_file_io.h	15 Jun 2003 00:05:26 -0000	1.141
  +++ apr_file_io.h	7 Jul 2003 22:44:11 -0000	1.142
  @@ -657,6 +657,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.
  
  
  
  1.3       +5 -4      apr/include/arch/win32/apr_arch_file_io.h
  
  Index: apr_arch_file_io.h
  ===================================================================
  RCS file: /home/cvs/apr/include/arch/win32/apr_arch_file_io.h,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- apr_arch_file_io.h	24 Jan 2003 17:15:56 -0000	1.2
  +++ apr_arch_file_io.h	7 Jul 2003 22:44:11 -0000	1.3
  @@ -133,10 +133,11 @@
   #endif
   
   /* Internal Flags for apr_file_open */
  -#define APR_OPENINFO     0x4000    /* Open without READ or WRITE access */
  -#define APR_OPENLINK     0x2000    /* Open a link itself, if supported */
  -#define APR_READCONTROL  0x1000    /* Read the file's owner/perms */
  -#define APR_WRITECONTROL 0x0800    /* Modifythe file's owner/perms */
  +#define APR_OPENINFO     0x00100000 /* Open without READ or WRITE access */
  +#define APR_OPENLINK     0x00200000 /* Open a link itself, if supported */
  +#define APR_READCONTROL  0x00400000 /* Read the file's owner/perms */
  +#define APR_WRITECONTROL 0x00800000 /* Modifythe file's owner/perms */
  +#define APR_WRITEATTRS   0x01000000 /* Modify the file's attributes */
   
   /* Entries missing from the MSVC 5.0 Win32 SDK:
    */
  
  
  
  1.11      +48 -0     apr/test/testfileinfo.c
  
  Index: testfileinfo.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testfileinfo.c,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- testfileinfo.c	7 Feb 2003 12:33:00 -0000	1.10
  +++ testfileinfo.c	7 Jul 2003 22:44:11 -0000	1.11
  @@ -239,6 +239,53 @@
       apr_file_close(thefile);
   }
   
  +static void test_mtime_set(CuTest *tc)
  +{
  +    apr_file_t *thefile;
  +    apr_finfo_t finfo;
  +    apr_time_t epoch = 0;
  +    apr_status_t rv;
  +
  +    /* This test sort of depends on the system clock being at least
  +     * marginally ccorrect; We'll be setting the modification time to
  +     * the epoch.
  +     */
  +    rv = apr_file_open(&thefile, NEWFILENAME,
  +                       APR_READ | APR_WRITE | APR_CREATE | APR_TRUNCATE
  +                       | APR_BUFFERED | APR_DELONCLOSE,
  +                       APR_OS_DEFAULT, p);
  +    apr_assert_success(tc, "open file", rv);
  +
  +    /* Check that the current mtime is not the epoch */
  +    rv = apr_stat(&finfo, NEWFILENAME, APR_FINFO_MTIME, p);
  +    if (rv  == APR_INCOMPLETE) {
  +        char *str;
  +	int i;
  +        str = apr_pstrdup(p, "APR_INCOMPLETE:  Missing ");
  +        for (i = 0; vfi[i].bits; ++i) {
  +            if (vfi[i].bits & ~finfo.valid) {
  +                str = apr_pstrcat(p, str, vfi[i].description, " ", NULL);
  +            }
  +        }
  +        CuFail(tc, str);
  +    }
  +    apr_assert_success(tc, "get initial mtime", rv);
  +    CuAssertTrue(tc, finfo.mtime != epoch);
  +
  +    /* Reset the mtime to the epoch and verify the result.
  +     * Note: we blindly assume that if the first apr_stat succeeded,
  +     * the second one will, too.
  +     */
  +    rv = apr_file_mtime_set(NEWFILENAME, epoch, p);
  +    apr_assert_success(tc, "set mtime", rv);
  +
  +    rv = apr_stat(&finfo, NEWFILENAME, APR_FINFO_MTIME, p);
  +    apr_assert_success(tc, "get modified mtime", rv);
  +    CuAssertTrue(tc, finfo.mtime == epoch);
  +
  +    apr_file_close(thefile);
  +}
  +
   CuSuite *testfileinfo(void)
   {
       CuSuite *suite = CuSuiteNew("File Info");
  @@ -247,6 +294,7 @@
       SUITE_ADD_TEST(suite, test_stat);
       SUITE_ADD_TEST(suite, test_stat_eq_finfo);
       SUITE_ADD_TEST(suite, test_buffered_write_size);
  +    SUITE_ADD_TEST(suite, test_mtime_set);
   
       return suite;
   }
  
  
  

Mime
View raw message