Skip to content

Commit

Permalink
Add Changelog BC Break note
Browse files Browse the repository at this point in the history
  • Loading branch information
romainneutron committed Jun 18, 2012
1 parent 9355c28 commit bd4799b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,4 +4,5 @@ CHANGELOG
2.1.0
-----

* 24eb396 : BC Break : mkdir() function now throws exception in case of failure instead of returning Boolean value
* created the component
54 changes: 28 additions & 26 deletions Filesystem.php
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\Filesystem;

use Symfony\Component\Filesystem\Exception\IOException;

/**
* Provides basic utility to manipulate the file system.
*
Expand All @@ -29,7 +31,7 @@ class Filesystem
* @param string $targetFile The target filename
* @param array $override Whether to override an existing file or not
*
* @throws Exception\IOException When copy fails
* @throws IOException When copy fails
*/
public function copy($originFile, $targetFile, $override = false)
{
Expand All @@ -43,7 +45,7 @@ public function copy($originFile, $targetFile, $override = false)

if ($doCopy) {
if (true !== @copy($originFile, $targetFile)) {
throw new Exception\IOException(sprintf('Failed to copy %s to %s', $originFile, $targetFile));
throw new IOException(sprintf('Failed to copy %s to %s', $originFile, $targetFile));
}
}
}
Expand All @@ -54,7 +56,7 @@ public function copy($originFile, $targetFile, $override = false)
* @param string|array|\Traversable $dirs The directory path
* @param integer $mode The directory mode
*
* @throws Exception\IOException On any directory creation failure
* @throws IOException On any directory creation failure
*/
public function mkdir($dirs, $mode = 0777)
{
Expand All @@ -64,7 +66,7 @@ public function mkdir($dirs, $mode = 0777)
}

if (true !== @mkdir($dir, $mode, true)) {
throw new Exception\IOException(sprintf('Failed to create %s', $dir));
throw new IOException(sprintf('Failed to create %s', $dir));
}
}
}
Expand Down Expand Up @@ -94,7 +96,7 @@ public function exists($files)
* @param integer $time The touch time as a unix timestamp
* @param integer $atime The access time as a unix timestamp
*
* @throws Exception\IOException When touch fails
* @throws IOException When touch fails
*/
public function touch($files, $time = null, $atime = null)
{
Expand All @@ -104,7 +106,7 @@ public function touch($files, $time = null, $atime = null)

foreach ($this->toIterator($files) as $file) {
if (true !== @touch($file, $time, $atime)) {
throw new Exception\IOException(sprintf('Failed to touch %s', $file));
throw new IOException(sprintf('Failed to touch %s', $file));
}
}
}
Expand All @@ -114,7 +116,7 @@ public function touch($files, $time = null, $atime = null)
*
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to remove
*
* @throws Exception\IOException When removal fails
* @throws IOException When removal fails
*/
public function remove($files)
{
Expand All @@ -129,17 +131,17 @@ public function remove($files)
$this->remove(new \FilesystemIterator($file));

if (true !== @rmdir($file)) {
throw new Exception\IOException(sprintf('Failed to remove directory %s', $file));
throw new IOException(sprintf('Failed to remove directory %s', $file));
}
} else {
// https://bugs.php.net/bug.php?id=52176
if (defined('PHP_WINDOWS_VERSION_MAJOR') && is_dir($file)) {
if (true !== @rmdir($file)) {
throw new Exception\IOException(sprintf('Failed to remove file %s', $file));
throw new IOException(sprintf('Failed to remove file %s', $file));
}
} else {
if (true !== @unlink($file)) {
throw new Exception\IOException(sprintf('Failed to remove file %s', $file));
throw new IOException(sprintf('Failed to remove file %s', $file));
}
}
}
Expand All @@ -154,7 +156,7 @@ public function remove($files)
* @param integer $umask The mode mask (octal)
* @param Boolean $recursive Whether change the mod recursively or not
*
* @throws Exception\IOException When the change fail
* @throws IOException When the change fail
*/
public function chmod($files, $mode, $umask = 0000, $recursive = false)
{
Expand All @@ -163,7 +165,7 @@ public function chmod($files, $mode, $umask = 0000, $recursive = false)
$this->chmod(new \FilesystemIterator($file), $mode, $umask, true);
}
if (true !== @chmod($file, $mode & ~$umask)) {
throw new Exception\IOException(sprintf('Failed to chmod file %s', $file));
throw new IOException(sprintf('Failed to chmod file %s', $file));
}
}
}
Expand All @@ -175,7 +177,7 @@ public function chmod($files, $mode, $umask = 0000, $recursive = false)
* @param string $user The new owner user name
* @param Boolean $recursive Whether change the owner recursively or not
*
* @throws Exception\IOException When the change fail
* @throws IOException When the change fail
*/
public function chown($files, $user, $recursive = false)
{
Expand All @@ -185,11 +187,11 @@ public function chown($files, $user, $recursive = false)
}
if (is_link($file) && function_exists('lchown')) {
if (true !== @lchown($file, $user)) {
throw new Exception\IOException(sprintf('Failed to chown file %s', $file));
throw new IOException(sprintf('Failed to chown file %s', $file));
}
} else {
if (true !== @chown($file, $user)) {
throw new Exception\IOException(sprintf('Failed to chown file %s', $file));
throw new IOException(sprintf('Failed to chown file %s', $file));
}
}
}
Expand All @@ -202,7 +204,7 @@ public function chown($files, $user, $recursive = false)
* @param string $group The group name
* @param Boolean $recursive Whether change the group recursively or not
*
* @throws Exception\IOException When the change fail
* @throws IOException When the change fail
*/
public function chgrp($files, $group, $recursive = false)
{
Expand All @@ -212,11 +214,11 @@ public function chgrp($files, $group, $recursive = false)
}
if (is_link($file) && function_exists('lchgrp')) {
if (true !== @lchgrp($file, $group)) {
throw new Exception\IOException(sprintf('Failed to chgrp file %s', $file));
throw new IOException(sprintf('Failed to chgrp file %s', $file));
}
} else {
if (true !== @chgrp($file, $group)) {
throw new Exception\IOException(sprintf('Failed to chgrp file %s', $file));
throw new IOException(sprintf('Failed to chgrp file %s', $file));
}
}
}
Expand All @@ -228,18 +230,18 @@ public function chgrp($files, $group, $recursive = false)
* @param string $origin The origin filename
* @param string $target The new filename
*
* @throws Exception\IOException When target file already exists
* @throws Exception\IOException When origin cannot be renamed
* @throws IOException When target file already exists
* @throws IOException When origin cannot be renamed
*/
public function rename($origin, $target)
{
// we check that target does not exist
if (is_readable($target)) {
throw new Exception\IOException(sprintf('Cannot rename because the target "%s" already exist.', $target));
throw new IOException(sprintf('Cannot rename because the target "%s" already exist.', $target));
}

if (true !== @rename($origin, $target)) {
throw new Exception\IOException(sprintf('Cannot rename "%s" to "%s".', $origin, $target));
throw new IOException(sprintf('Cannot rename "%s" to "%s".', $origin, $target));
}
}

Expand All @@ -250,7 +252,7 @@ public function rename($origin, $target)
* @param string $targetDir The symbolic link name
* @param Boolean $copyOnWindows Whether to copy files if on Windows
*
* @throws Exception\IOException When symlink fails
* @throws IOException When symlink fails
*/
public function symlink($originDir, $targetDir, $copyOnWindows = false)
{
Expand All @@ -273,7 +275,7 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)

if (!$ok) {
if (true !== @symlink($originDir, $targetDir)) {
throw new Exception\IOException(sprintf('Failed to create symbolic link from %s to %s', $originDir, $targetDir));
throw new IOException(sprintf('Failed to create symbolic link from %s to %s', $originDir, $targetDir));
}
}
}
Expand Down Expand Up @@ -322,7 +324,7 @@ public function makePathRelative($endPath, $startPath)
* - $options['override'] Whether to override an existing file on copy or not (see copy())
* - $options['copy_on_windows'] Whether to copy files instead of links on Windows (see symlink())
*
* @throws Exception\IOException When file type is unknown
* @throws IOException When file type is unknown
*/
public function mirror($originDir, $targetDir, \Traversable $iterator = null, $options = array())
{
Expand All @@ -349,7 +351,7 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
} elseif (is_file($file) || ($copyOnWindows && is_link($file))) {
$this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
} else {
throw new Exception\IOException(sprintf('Unable to guess "%s" file type.', $file));
throw new IOException(sprintf('Unable to guess "%s" file type.', $file));
}
}
}
Expand Down

0 comments on commit bd4799b

Please sign in to comment.