Skip to content

Loading…

Fix win unlink #478

Merged
merged 2 commits into from

2 participants

@hans-d

No description provided.

hans-d added some commits
@hans-d hans-d Fix unlinking readonly files throwing an Permission denied exception …
…on Windows.

The file is checked before an unlink is tried. (this will make the tests run slower but is prefered over a if (!unlink { chmod; unlink }.
See also: http://stringoftheseus.com/blog/2010/12/22/php-unlink-permisssion-denied-error-on-windows/

Signed-off-by: Hans Donner <hans.donner@pobox.com>
3beab8c
@hans-d hans-d simplify if else and use $item->isWritable()
Signed-off-by: Hans Donner <hans.donner@pobox.com>
59369e1
@gwoo gwoo merged commit 6c5ff22 into UnionOfRAD:dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 23, 2012
  1. @hans-d

    Fix unlinking readonly files throwing an Permission denied exception …

    hans-d committed
    …on Windows.
    
    The file is checked before an unlink is tried. (this will make the tests run slower but is prefered over a if (!unlink { chmod; unlink }.
    See also: http://stringoftheseus.com/blog/2010/12/22/php-unlink-permisssion-denied-error-on-windows/
    
    Signed-off-by: Hans Donner <hans.donner@pobox.com>
  2. @hans-d

    simplify if else and use $item->isWritable()

    hans-d committed
    Signed-off-by: Hans Donner <hans.donner@pobox.com>
Showing with 13 additions and 1 deletion.
  1. +13 −1 test/Unit.php
View
14 test/Unit.php
@@ -988,6 +988,11 @@ protected function _arrayPermute($items, $perms = array()) {
* Uses `DIRECTORY_SEPARATOR` as `getPathname()` is used in a a direct
* string comparison. The method may contain slashes and backslashes.
*
+ * If the file to unlink is readonly, it throws a exception (Permission denied) on Windows.
+ * So, the file is checked before an unlink is tried. (this will make the tests run slower
+ * but is prefered over a if (!unlink { chmod; unlink }.
+ * See: http://stringoftheseus.com/blog/2010/12/22/php-unlink-permisssion-denied-error-on-windows/
+ *
* @param string $path Path to directory with contents to remove. If first
* character is NOT a slash (`/`) or a Windows drive letter (`C:`)
* prepends `LITHIUM_APP_PATH/resources/tmp/`.
@@ -1010,7 +1015,14 @@ protected function _cleanUp($path = null) {
if ($empty || $iterator->isDot()) {
continue;
}
- ($item->isDir()) ? rmdir($item->getPathname()) : unlink($item->getPathname());
+ if ($item->isDir()) {
+ rmdir($item->getPathname());
+ continue;
+ }
+ if (!$item->isWritable()) {
+ chmod($item->getPathname(), 0777);
+ }
+ unlink($item->getPathname());
}
}
Something went wrong with that request. Please try again.