diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-08-17 22:05:22 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-08-17 22:05:22 +0000 |
commit | 755913e0b7fc552126b3cf2d5074b911f24f996b (patch) | |
tree | 0b7ba3fa4aa81fd7d01a28873bb04aac4efe73e5 /includes | |
parent | 16c888a917c889faf6d29fa6162201c9c8810f2f (diff) | |
download | brdo-755913e0b7fc552126b3cf2d5074b911f24f996b.tar.gz brdo-755913e0b7fc552126b3cf2d5074b911f24f996b.tar.bz2 |
- Patch #443286 by c960657, Damien Tournoud, drifter, webkenny, scor: international characters break file handling.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/file.inc | 70 | ||||
-rw-r--r-- | includes/filetransfer/ftp.inc | 4 | ||||
-rw-r--r-- | includes/filetransfer/local.inc | 8 | ||||
-rw-r--r-- | includes/stream_wrappers.inc | 6 |
4 files changed, 76 insertions, 12 deletions
diff --git a/includes/file.inc b/includes/file.inc index 0d4af7693..328cf08de 100644 --- a/includes/file.inc +++ b/includes/file.inc @@ -943,6 +943,10 @@ function file_create_filename($basename, $directory) { // Strip control characters (ASCII value < 32). Though these are allowed in // some filesystems, not many applications handle them well. $basename = preg_replace('/[\x00-\x1F]/u', '_', $basename); + if (substr(PHP_OS, 0, 3) == 'WIN') { + // These characters are not allowed in Windows filenames + $basename = str_replace(array(':', '*', '?', '"', '<', '>', '|'), '_', $basename); + } // A URI or path may already have a trailing slash or look like "public://". if (substr($directory, -1) == '/') { @@ -1042,7 +1046,7 @@ function file_unmanaged_delete($path) { return FALSE; } if (is_file($path)) { - return unlink($path); + return drupal_unlink($path); } // Return TRUE for non-existent file, but log that nothing was actually // deleted, as the current state is the intended result. @@ -1090,7 +1094,8 @@ function file_unmanaged_delete_recursive($path) { file_unmanaged_delete_recursive($entry_path); } $dir->close(); - return rmdir($path); + + return drupal_rmdir($path); } return file_unmanaged_delete($path); } @@ -1893,6 +1898,36 @@ function drupal_chmod($uri, $mode = NULL) { } /** + * Deletes a file. + * + * PHP's unlink() is broken on Windows, as it can fail to remove a file + * when it has a read-only flag set. + * + * @param $uri + * A URI or pathname. + * @param $context + * Refer to http://php.net/manual/en/ref.stream.php + * + * @return + * Boolean TRUE on success, or FALSE on failure. + * + * @see unlink() + * @ingroup php_wrappers + */ +function drupal_unlink($uri, $context = NULL) { + $scheme = file_uri_scheme($uri); + if ((!$scheme || !file_stream_wrapper_valid_scheme($scheme)) && (substr(PHP_OS, 0, 3) == 'WIN')) { + chmod($uri, 0600); + } + if ($context) { + return unlink($uri, $context); + } + else { + return unlink($uri); + } +} + +/** * Returns the absolute path of a file or directory * * PHP's realpath() does not properly support streams, so this function @@ -1988,7 +2023,6 @@ function drupal_dirname($uri) { * @ingroup php_wrappers */ function drupal_mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL) { - if (is_null($mode)) { $mode = variable_get('file_chmod_directory', 0775); } @@ -2002,6 +2036,36 @@ function drupal_mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL) { } /** + * Remove a directory. + * + * PHP's rmdir() is broken on Windows, as it can fail to remove a directory + * when it has a read-only flag set. + * + * @param $uri + * A URI or pathname. + * @param $context + * Refer to http://php.net/manual/en/ref.stream.php + * + * @return + * Boolean TRUE on success, or FALSE on failure. + * + * @see rmdir() + * @ingroup php_wrappers + */ +function drupal_rmdir($uri, $context = NULL) { + $scheme = file_uri_scheme($uri); + if ((!$scheme || !file_stream_wrapper_valid_scheme($scheme)) && (substr(PHP_OS, 0, 3) == 'WIN')) { + chmod($uri, 0700); + } + if ($context) { + return rmdir($uri, $context); + } + else { + return rmdir($uri); + } +} + +/** * Creates a file with a unique filename in the specified directory. * * PHP's tempnam() does not return a URI like we want. This function diff --git a/includes/filetransfer/ftp.inc b/includes/filetransfer/ftp.inc index b6046b2de..d370e09db 100644 --- a/includes/filetransfer/ftp.inc +++ b/includes/filetransfer/ftp.inc @@ -77,7 +77,7 @@ class FileTransferFTPWrapper extends FileTransferFTP { } } closedir($dh); - if (!rmdir($this->connection . $directory)) { + if (!drupal_rmdir($this->connection . $directory)) { $exception = new FileTransferException('Cannot remove @directory.', NULL, array('@directory' => $directory)); throw $exception; } @@ -91,7 +91,7 @@ class FileTransferFTPWrapper extends FileTransferFTP { } function removeFileJailed($destination) { - if (!@unlink($this->connection . '/' .$destination)) { + if (!@drupal_unlink($this->connection . '/' .$destination)) { throw new FileTransferException('Cannot remove @destination', NULL, array('@destination' => $destination)); } } diff --git a/includes/filetransfer/local.inc b/includes/filetransfer/local.inc index 14e246671..8cad200b1 100644 --- a/includes/filetransfer/local.inc +++ b/includes/filetransfer/local.inc @@ -33,23 +33,23 @@ class FileTransferLocal extends FileTransfer implements FileTransferChmodInterfa } foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST) as $filename => $file) { if ($file->isDir()) { - if (@!rmdir($filename)) { + if (@!drupal_rmdir($filename)) { throw new FileTransferException('Cannot remove directory %directory.', NULL, array('%directory' => $filename)); } } elseif ($file->isFile()) { - if (@!unlink($filename)) { + if (@!drupal_unlink($filename)) { throw new FileTransferException('Cannot remove file %file.', NULL, array('%file' => $filename)); } } } - if (@!rmdir($directory)) { + if (@!drupal_rmdir($directory)) { throw new FileTransferException('Cannot remove directory %directory.', NULL, array('%directory' => $directory)); } } protected function removeFileJailed($file) { - if (@!unlink($file)) { + if (@!drupal_unlink($file)) { throw new FileTransferException('Cannot remove file %file.', NULL, array('%file' => $file)); } } diff --git a/includes/stream_wrappers.inc b/includes/stream_wrappers.inc index a78374c96..f49d3bc29 100644 --- a/includes/stream_wrappers.inc +++ b/includes/stream_wrappers.inc @@ -539,7 +539,7 @@ abstract class DrupalLocalStreamWrapper implements DrupalStreamWrapperInterface */ public function unlink($uri) { $this->uri = $uri; - return unlink($this->getLocalPath()); + return drupal_unlink($this->getLocalPath()); } /** @@ -636,10 +636,10 @@ abstract class DrupalLocalStreamWrapper implements DrupalStreamWrapperInterface public function rmdir($uri, $options) { $this->uri = $uri; if ($options & STREAM_REPORT_ERRORS) { - return rmdir($this->getLocalPath()); + return drupal_rmdir($this->getLocalPath()); } else { - return @rmdir($this->getLocalPath()); + return @drupal_rmdir($this->getLocalPath()); } } |