Skip to content

Commit

Permalink
FileSystem: messages use normalized paths (#250)
Browse files Browse the repository at this point in the history
Co-authored-by: David Grudl <david@grudl.com>
Co-authored-by: Karel Horsk媒 <karel.horsky@centrum.cz>
  • Loading branch information
3 people committed Nov 24, 2021
1 parent fc81c4a commit c363b11
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/Utils/FileSystem.php
Expand Up @@ -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()
));
Expand All @@ -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);
Expand All @@ -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()
));
}
Expand All @@ -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()
));
}
Expand All @@ -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()
));
}
Expand All @@ -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));
Expand All @@ -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()
));
}
Expand All @@ -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()
));
}
Expand All @@ -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()
));
Expand All @@ -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()
));
Expand All @@ -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)));
}
}

Expand Down

0 comments on commit c363b11

Please sign in to comment.