Exemple #1
0
 public function touch($path, $mtime = null, $atime = null)
 {
     $fullPath = $this->getFullPath($path);
     if (!file_exists($fullPath)) {
         $dir = $this->getDir($fullPath);
         if (!file_exists($dir)) {
             throw FileException::ENOENT();
         } elseif (!is_dir($dir)) {
             throw FileException::ENOTDIR();
         }
     }
     if ($mtime !== null && $atime !== null) {
         return touch($fullPath, $mtime, $atime);
     } elseif ($mtime !== null) {
         return touch($fullPath, $mtime);
     } else {
         return touch($fullPath);
     }
 }
Exemple #2
0
 public function mkdir($path, $mode = 0777, $options = null)
 {
     $path = Util\Path::normalise("/{$path}");
     $target = $this->getInternalNode($path);
     if ($target) {
         throw FileException::EEXIST();
     }
     if ($options & STREAM_MKDIR_RECURSIVE) {
         $bits = "";
         $make = false;
         foreach (Util\Path::split($path) as $part) {
             $bits .= "/{$part}";
             if (!$make) {
                 $node = $this->getInternalNode($bits);
                 if (!$node) {
                     $make = true;
                 }
             }
             if ($make) {
                 if (!$this->mkdir($bits, $mode, $options & ~STREAM_MKDIR_RECURSIVE)) {
                     throw new \Exception();
                 }
             }
         }
         return true;
     } else {
         $dir = $this->getInternalNode(dirname($path));
         if (!$dir) {
             throw FileException::ENOENT();
         } elseif ($dir->node->type != Node::DIR) {
             throw FileException::ENOTDIR();
         }
         $node = $this->createNode($path, Node::DIR, ['perms' => $mode]);
         $dir->data[basename($path)] = (object) ['node' => $node, 'data' => [], 'len' => 0];
         return true;
     }
 }