From 2f261e55bd6a12057442045bf2c249806abc1d02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Wed, 24 Nov 2021 16:33:28 +0100 Subject: [PATCH] FileSystem: messages use normalized paths (#250) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: David Grudl Co-authored-by: Karel Horský --- src/Utils/FileSystem.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Utils/FileSystem.php b/src/Utils/FileSystem.php index eba20e84f..9abb9f60c 100644 --- a/src/Utils/FileSystem.php +++ b/src/Utils/FileSystem.php @@ -28,7 +28,7 @@ public static function createDir(string $dir, int $mode = 0777): void if (!is_dir($dir) && !@mkdir($dir, $mode, true) && !is_dir($dir)) { // @ - dir may already exist throw new Nette\IOException(sprintf( "Unable to create directory '%s' with mode %s. %s", - $dir, + self::normalizePath($dir), decoct($mode), Helpers::getLastError() )); @@ -44,10 +44,10 @@ public static function createDir(string $dir, int $mode = 0777): void public static function copy(string $origin, string $target, bool $overwrite = true): void { if (stream_is_local($origin) && !file_exists($origin)) { - throw new Nette\IOException(sprintf("File or directory '%s' not found.", $origin)); + throw new Nette\IOException(sprintf("File or directory '%s' not found.", self::normalizePath($origin))); } elseif (!$overwrite && file_exists($target)) { - throw new Nette\InvalidStateException(sprintf("File or directory '%s' already exists.", $target)); + throw new Nette\InvalidStateException(sprintf("File or directory '%s' already exists.", self::normalizePath($target))); } elseif (is_dir($origin)) { static::createDir($target); @@ -71,8 +71,8 @@ public static function copy(string $origin, string $target, bool $overwrite = tr ) { // @ is escalated to exception throw new Nette\IOException(sprintf( "Unable to copy file '%s' to '%s'. %s", - $origin, - $target, + self::normalizePath($origin), + self::normalizePath($target), Helpers::getLastError() )); } @@ -91,7 +91,7 @@ public static function delete(string $path): void if (!@$func($path)) { // @ is escalated to exception throw new Nette\IOException(sprintf( "Unable to delete '%s'. %s", - $path, + self::normalizePath($path), Helpers::getLastError() )); } @@ -103,7 +103,7 @@ public static function delete(string $path): void if (!@rmdir($path)) { // @ is escalated to exception throw new Nette\IOException(sprintf( "Unable to delete directory '%s'. %s", - $path, + self::normalizePath($path), Helpers::getLastError() )); } @@ -119,10 +119,10 @@ public static function delete(string $path): void public static function rename(string $origin, string $target, bool $overwrite = true): void { if (!$overwrite && file_exists($target)) { - throw new Nette\InvalidStateException(sprintf("File or directory '%s' already exists.", $target)); + throw new Nette\InvalidStateException(sprintf("File or directory '%s' already exists.", self::normalizePath($target))); } elseif (!file_exists($origin)) { - throw new Nette\IOException(sprintf("File or directory '%s' not found.", $origin)); + throw new Nette\IOException(sprintf("File or directory '%s' not found.", self::normalizePath($origin))); } else { static::createDir(dirname($target)); @@ -132,8 +132,8 @@ public static function rename(string $origin, string $target, bool $overwrite = if (!@rename($origin, $target)) { // @ is escalated to exception throw new Nette\IOException(sprintf( "Unable to rename file or directory '%s' to '%s'. %s", - $origin, - $target, + self::normalizePath($origin), + self::normalizePath($target), Helpers::getLastError() )); } @@ -151,7 +151,7 @@ public static function read(string $file): string if ($content === false) { throw new Nette\IOException(sprintf( "Unable to read file '%s'. %s", - $file, + self::normalizePath($file), Helpers::getLastError() )); } @@ -169,14 +169,14 @@ public static function write(string $file, string $content, ?int $mode = 0666): if (@file_put_contents($file, $content) === false) { // @ is escalated to exception throw new Nette\IOException(sprintf( "Unable to write file '%s'. %s", - $file, + self::normalizePath($file), Helpers::getLastError() )); } if ($mode !== null && !@chmod($file, $mode)) { // @ is escalated to exception throw new Nette\IOException(sprintf( "Unable to chmod file '%s' to mode %s. %s", - $file, + self::normalizePath($file), decoct($mode), Helpers::getLastError() )); @@ -194,7 +194,7 @@ public static function makeWritable(string $path, int $dirMode = 0777, int $file if (!@chmod($path, $fileMode)) { // @ is escalated to exception throw new Nette\IOException(sprintf( "Unable to chmod file '%s' to mode %s. %s", - $path, + self::normalizePath($path), decoct($fileMode), Helpers::getLastError() )); @@ -206,13 +206,13 @@ public static function makeWritable(string $path, int $dirMode = 0777, int $file if (!@chmod($path, $dirMode)) { // @ is escalated to exception throw new Nette\IOException(sprintf( "Unable to chmod directory '%s' to mode %s. %s", - $path, + self::normalizePath($path), decoct($dirMode), Helpers::getLastError() )); } } else { - throw new Nette\IOException(sprintf("File or directory '%s' not found.", $path)); + throw new Nette\IOException(sprintf("File or directory '%s' not found.", self::normalizePath($path))); } }