示例#1
0
 /**
  * @param bool $overwrite Set to TRUE to try overwriting the file if it already exists
  * @return bool
  * @throws EyeIOException
  */
 public function createNewFile($overwrite = false)
 {
     if ($this->realFile === null) {
         throw new EyeUnsupportedOperationException(__METHOD__ . ' on ' . $this->path);
     }
     if ($this->isRoot()) {
         throw new EyeIOException($this->path . ' is the root folder.');
     }
     if ($this->exists()) {
         if (!$overwrite) {
             throw new EyeFileAlreadyExistsException($this->path . ' already exists.');
         } else {
             $this->delete();
         }
     } else {
         $this->getParentFile()->checkWritePermission();
     }
     try {
         if ($this->realFile->createNewFile($overwrite)) {
             MetaManager::getInstance()->deleteMeta($this);
             $meta = MetaManager::getInstance()->getNewMetaDataInstance($this);
             if ($meta !== null) {
                 $currentUser = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser();
                 $group = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosGroup();
                 $meta->set(self::METADATA_KEY_OWNER, $currentUser->getName());
                 $meta->set(self::METADATA_KEY_GROUP, $group->getName());
                 $meta->set(self::METADATA_KEY_CREATIONTIME, time());
                 $meta->set(self::METADATA_KEY_MODIFICATIONTIME, time());
                 $meta->set(self::METADATA_KEY_PERMISSIONS, AdvancedPathLib::permsToUnix(self::PERMISSIONS_MASK_FILE & ~$this->getUMask()));
                 $this->setMeta($meta);
             }
             //notify listeners
             $this->fireEvent('fileCreated', new FileEvent($this));
             return true;
         }
     } catch (EyeIOException $e) {
         throw new EyeIOException('Unable to create virtual file at ' . $this->path, 0, $e);
     }
     throw new EyeUnknownErrorException('Unable to create file at ' . $this->path . '.');
 }