php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49047 The function touch() fails on directories.
Submitted: 2009-07-24 12:48 UTC Modified: 2009-08-25 09:17 UTC
From: RQuadling at GMail dot com Assigned: pajoye
Status: Closed Package: Filesystem function related
PHP Version: 5.3SVN-2009-07-24 (snap) OS: win32 only - Windows XP SP3
Private report: No CVE-ID:
 [2009-07-24 12:48 UTC] RQuadling at GMail dot com
Description:
------------
Trying to touch() a win32 folder fails.

In tracking this back through the source, I think the issue is that 
PHP is calling the external utime() function.

For my build (I'm a novice so please bear with me), I see that ...

HAVE_UTIME
TSRM_WIN32

are both set, but 

VIRTUAL_DIR

is not.

This is a repeat of bug#35980, but as that bug is closed and the 
example code below doesn't work, I assume this is a new bug.



So, in TSRM/tsrm_virtual_cwd.h, the call that is being made is ...

#ifdef VIRTUAL_DIR
...
#if HAVE_UTIME
#define VCWD_UTIME(path, time) virtual_utime(path, time TSRMLS_CC)
#endif
...
#else
...
#if HAVE_UTIME
#define VCWD_UTIME(path, time) utime(path, time)
#endif
...
#endif

utime(path, time)

I think this is the external call and as such will fail. I think that 
is why the virtual version exists (which in turn calls win32_utime)



Reproduce code:
---------------
<?php
$s_Directory = 'C:\\Test';
$dt_DOB = strtotime('2008-10-19 18:43');

if (file_exists($s_Directory) && !rmdir($s_Directory)) {
  die("Failed to delete $s_Directory");
}

echo "Create $s_Directory", PHP_EOL;
if (!mkdir($s_Directory)) {
  die("Failed to create $s_Directory");
} else {
  echo "Created $s_Directory", PHP_EOL;
}

echo "Touch $s_Directory : ", date('r', $dt_DOB), PHP_EOL;
if (!touch($s_Directory, $dt_DOB)) {
  die("Failed to touch $s_Directory");
} else {
  echo "Touched $s_Directory", PHP_EOL;
}

Expected result:
----------------
Create C:\Test
Created C:\Test
Touch C:\Test : Sun, 19 Oct 2008 18:43:00 +0100
Touched C:\Test

Actual result:
--------------
Create C:\Test
Created C:\Test
Touch C:\Test : Sun, 19 Oct 2008 18:43:00 +0100

Warning: touch(): Utime failed: Permission denied in Z:\touchdir.php on 
line 22
Failed to touch C:\Test

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-24 16:33 UTC] pajoye@php.net
commit on its way
 [2009-08-25 09:16 UTC] svn@php.net
Automatic comment from SVN on behalf of pajoye
Revision: http://svn.php.net/viewvc/?view=revision&revision=287673
Log: - fix #49047, touch may fail on directory
 [2009-08-25 09:17 UTC] pajoye@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 16 10:02:09 2014 UTC