@@ -100,6 +100,10 @@ public function mkdir($dirs, $mode = 0777)
100
100
public function exists ($ files )
101
101
{
102
102
foreach ($ this ->toIterator ($ files ) as $ file ) {
103
+ if ('\\' === DIRECTORY_SEPARATOR AND strlen ($ file ) > 258 ) {
104
+ throw new IOException (sprintf ('Could not check if file exist because path length exceeds 258 characters for file "%s" ' , $ file ));
105
+ }
106
+
103
107
if (!file_exists ($ file )) {
104
108
return false ;
105
109
}
@@ -139,7 +143,7 @@ public function remove($files)
139
143
$ files = iterator_to_array ($ this ->toIterator ($ files ));
140
144
$ files = array_reverse ($ files );
141
145
foreach ($ files as $ file ) {
142
- if (!file_exists ($ file ) && !is_link ($ file )) {
146
+ if (!$ this -> exists ($ file ) && !is_link ($ file )) {
143
147
continue ;
144
148
}
145
149
@@ -157,7 +161,8 @@ public function remove($files)
157
161
}
158
162
} else {
159
163
if (true !== @unlink ($ file )) {
160
- throw new IOException (sprintf ('Failed to remove file %s ' , $ file ));
164
+ $ error = error_get_last ();
165
+ throw new IOException (sprintf ('Failed to remove file "%s": %s. ' , $ file , $ error ['message ' ]));
161
166
}
162
167
}
163
168
}
@@ -253,7 +258,7 @@ public function chgrp($files, $group, $recursive = false)
253
258
public function rename ($ origin , $ target , $ overwrite = false )
254
259
{
255
260
// we check that target does not exist
256
- if (!$ overwrite && is_readable ($ target )) {
261
+ if (!$ overwrite && $ this -> isReadable ($ target )) {
257
262
throw new IOException (sprintf ('Cannot rename because the target "%s" already exist. ' , $ target ));
258
263
}
259
264
@@ -262,6 +267,22 @@ public function rename($origin, $target, $overwrite = false)
262
267
}
263
268
}
264
269
270
+ /**
271
+ * Tells whether a file exists and is readable.
272
+ *
273
+ * @param string $filename Path to the file.
274
+ *
275
+ * @throws IOException When windows path is longer than 258 characters
276
+ */
277
+ private function isReadable ($ filename )
278
+ {
279
+ if ('\\' === DIRECTORY_SEPARATOR AND strlen ($ filename ) > 258 ) {
280
+ throw new IOException (sprintf ('Could not check if file is readable because path length exceeds 258 characters for file "%s" ' , $ filename ));
281
+ }
282
+
283
+ return is_readable ($ filename );
284
+ }
285
+
265
286
/**
266
287
* Creates a symbolic link or copy a directory.
267
288
*
0 commit comments