PluginProbe
Packeta / 2.1
Packeta v2.1
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
← All changes | deps/nette/utils/src/Utils/FileSystem.php +15 -15 1.6.42.1 View file →
@@ -21,9 +21,9 @@
21 21 public static function createDir(string $dir, int $mode = 0777) : void
22 22 {
23 23 if (!\is_dir($dir) && !@\mkdir($dir, $mode, \true) && !\is_dir($dir)) {
24 24 // @ - dir may already exist
25 - throw new \Packetery\Nette\IOException("Unable to create directory '{$dir}' with mode " . \decoct($mode) . '. ' . Helpers::getLastError());
25 + throw new \Packetery\Nette\IOException(\sprintf("Unable to create directory '%s' with mode %s. %s", self::normalizePath($dir), \decoct($mode), Helpers::getLastError()));
26 26 }
27 27 }
28 28 /**
29 29 * Copies a file or a directory. Overwrites existing files and directories by default.
@@ -32,11 +32,11 @@
32 32 */
33 33 public static function copy(string $origin, string $target, bool $overwrite = \true) : void
34 34 {
35 35 if (\stream_is_local($origin) && !\file_exists($origin)) {
36 - throw new \Packetery\Nette\IOException("File or directory '{$origin}' not found.");
36 + throw new \Packetery\Nette\IOException(\sprintf("File or directory '%s' not found.", self::normalizePath($origin)));
37 37 } elseif (!$overwrite && \file_exists($target)) {
38 - throw new \Packetery\Nette\InvalidStateException("File or directory '{$target}' already exists.");
38 + throw new \Packetery\Nette\InvalidStateException(\sprintf("File or directory '%s' already exists.", self::normalizePath($target)));
39 39 } elseif (\is_dir($origin)) {
40 40 static::createDir($target);
41 41 foreach (new \FilesystemIterator($target) as $item) {
42 42 static::delete($item->getPathname());
@@ -51,9 +51,9 @@
51 51 } else {
52 52 static::createDir(\dirname($target));
53 53 if (($s = @\fopen($origin, 'rb')) && ($d = @\fopen($target, 'wb')) && @\stream_copy_to_stream($s, $d) === \false) {
54 54 // @ is escalated to exception
55 - throw new \Packetery\Nette\IOException("Unable to copy file '{$origin}' to '{$target}'. " . Helpers::getLastError());
55 + throw new \Packetery\Nette\IOException(\sprintf("Unable to copy file '%s' to '%s'. %s", self::normalizePath($origin), self::normalizePath($target), Helpers::getLastError()));
56 56 }
57 57 }
58 58 }
59 59 /**
@@ -65,9 +65,9 @@
65 65 if (\is_file($path) || \is_link($path)) {
66 66 $func = \DIRECTORY_SEPARATOR === '\\' && \is_dir($path) ? 'rmdir' : 'unlink';
67 67 if (!@$func($path)) {
68 68 // @ is escalated to exception
69 - throw new \Packetery\Nette\IOException("Unable to delete '{$path}'. " . Helpers::getLastError());
69 + throw new \Packetery\Nette\IOException(\sprintf("Unable to delete '%s'. %s", self::normalizePath($path), Helpers::getLastError()));
70 70 }
71 71 } elseif (\is_dir($path)) {
72 72 foreach (new \FilesystemIterator($path) as $item) {
73 73 static::delete($item->getPathname());
@@ -73,9 +73,9 @@
73 73 static::delete($item->getPathname());
74 74 }
75 75 if (!@\rmdir($path)) {
76 76 // @ is escalated to exception
77 - throw new \Packetery\Nette\IOException("Unable to delete directory '{$path}'. " . Helpers::getLastError());
77 + throw new \Packetery\Nette\IOException(\sprintf("Unable to delete directory '%s'. %s", self::normalizePath($path), Helpers::getLastError()));
78 78 }
79 79 }
80 80 }
81 81 /**
@@ -85,11 +85,11 @@
85 85 */
86 86 public static function rename(string $origin, string $target, bool $overwrite = \true) : void
87 87 {
88 88 if (!$overwrite && \file_exists($target)) {
89 - throw new \Packetery\Nette\InvalidStateException("File or directory '{$target}' already exists.");
89 + throw new \Packetery\Nette\InvalidStateException(\sprintf("File or directory '%s' already exists.", self::normalizePath($target)));
90 90 } elseif (!\file_exists($origin)) {
91 - throw new \Packetery\Nette\IOException("File or directory '{$origin}' not found.");
91 + throw new \Packetery\Nette\IOException(\sprintf("File or directory '%s' not found.", self::normalizePath($origin)));
92 92 } else {
93 93 static::createDir(\dirname($target));
94 94 if (\realpath($origin) !== \realpath($target)) {
95 95 static::delete($target);
@@ -95,9 +95,9 @@
95 95 static::delete($target);
96 96 }
97 97 if (!@\rename($origin, $target)) {
98 98 // @ is escalated to exception
99 - throw new \Packetery\Nette\IOException("Unable to rename file or directory '{$origin}' to '{$target}'. " . Helpers::getLastError());
99 + throw new \Packetery\Nette\IOException(\sprintf("Unable to rename file or directory '%s' to '%s'. %s", self::normalizePath($origin), self::normalizePath($target), Helpers::getLastError()));
100 100 }
101 101 }
102 102 }
103 103 /**
@@ -108,9 +108,9 @@
108 108 {
109 109 $content = @\file_get_contents($file);
110 110 // @ is escalated to exception
111 111 if ($content === \false) {
112 - throw new \Packetery\Nette\IOException("Unable to read file '{$file}'. " . Helpers::getLastError());
112 + throw new \Packetery\Nette\IOException(\sprintf("Unable to read file '%s'. %s", self::normalizePath($file), Helpers::getLastError()));
113 113 }
114 114 return $content;
115 115 }
116 116 /**
@@ -121,13 +121,13 @@
121 121 {
122 122 static::createDir(\dirname($file));
123 123 if (@\file_put_contents($file, $content) === \false) {
124 124 // @ is escalated to exception
125 - throw new \Packetery\Nette\IOException("Unable to write file '{$file}'. " . Helpers::getLastError());
125 + throw new \Packetery\Nette\IOException(\sprintf("Unable to write file '%s'. %s", self::normalizePath($file), Helpers::getLastError()));
126 126 }
127 127 if ($mode !== null && !@\chmod($file, $mode)) {
128 128 // @ is escalated to exception
129 - throw new \Packetery\Nette\IOException("Unable to chmod file '{$file}' to mode " . \decoct($mode) . '. ' . Helpers::getLastError());
129 + throw new \Packetery\Nette\IOException(\sprintf("Unable to chmod file '%s' to mode %s. %s", self::normalizePath($file), \decoct($mode), Helpers::getLastError()));
130 130 }
131 131 }
132 132 /**
133 133 * Fixes permissions to a specific file or directory. Directories can be fixed recursively.
@@ -137,9 +137,9 @@
137 137 {
138 138 if (\is_file($path)) {
139 139 if (!@\chmod($path, $fileMode)) {
140 140 // @ is escalated to exception
141 - throw new \Packetery\Nette\IOException("Unable to chmod file '{$path}' to mode " . \decoct($fileMode) . '. ' . Helpers::getLastError());
141 + throw new \Packetery\Nette\IOException(\sprintf("Unable to chmod file '%s' to mode %s. %s", self::normalizePath($path), \decoct($fileMode), Helpers::getLastError()));
142 142 }
143 143 } elseif (\is_dir($path)) {
144 144 foreach (new \FilesystemIterator($path) as $item) {
145 145 static::makeWritable($item->getPathname(), $dirMode, $fileMode);
@@ -145,12 +145,12 @@
145 145 static::makeWritable($item->getPathname(), $dirMode, $fileMode);
146 146 }
147 147 if (!@\chmod($path, $dirMode)) {
148 148 // @ is escalated to exception
149 - throw new \Packetery\Nette\IOException("Unable to chmod directory '{$path}' to mode " . \decoct($dirMode) . '. ' . Helpers::getLastError());
149 + throw new \Packetery\Nette\IOException(\sprintf("Unable to chmod directory '%s' to mode %s. %s", self::normalizePath($path), \decoct($dirMode), Helpers::getLastError()));
150 150 }
151 151 } else {
152 - throw new \Packetery\Nette\IOException("File or directory '{$path}' not found.");
152 + throw new \Packetery\Nette\IOException(\sprintf("File or directory '%s' not found.", self::normalizePath($path)));
153 153 }
154 154 }
155 155 /**
156 156 * Determines if the path is absolute.