public static function mkdir($path, $mode = 0777, $recursive = true)
{
- if (file_exists($path)) {
- return;
+ if (!file_exists($path)) {
+ try {
+ if (!mkdir($path, $mode, $recursive) && !is_dir($path)) {
+ throw new \RuntimeException(sprintf('Directory "%s" was not created', $path));
+ }
+ } catch (\Exception $e) {
+ throw new \RuntimeException(sprintf('Directory "%s" was not created. %s', $path, $e->getMessage()));
+ }
}
- mkdir($path, $mode, $recursive);
- return realpath($path);
+ return realpath($path).'/';
}
public static function humanReadableSize($size, $precision = 2)
<?php
namespace Cubist\Util\Files;
+
use SplFileInfo;
class VirtualDirectory
return $this;
}
+ /**
+ * @throws \Exception
+ */
public function sync($delete = false)
{
$existing = array();
+
foreach ($this->_directories as $to => $from) {
$this->_addDirectory($from, $to);
}
$existing[$to] = true;
}
if (!file_exists($to) || filesize($from) != filesize($to) || filemtime($from) > filemtime($to)) {
- copy($from, $to);
+ try {
+ copy($from, $to);
+ } catch (\Exception $e) {
+ throw new \Exception(sprintf('Failed to copy %s to %s', $from, $to));
+ }
}
}