コード例 #1
0
 /**
  * @covers InstanceStorage::getStorageMount
  * @covers InstanceStorage::getPrivateStorageMount
  * @covers InstanceStorage::getOwnerPrivateStorageMount
  * @covers InstanceStorage::getSnapshotMount
  */
 public function testStorageMounts()
 {
     $_instance = $this->_findInstance('dfe-test-case');
     $_testFile = '_test.file_';
     $_contents = 'test';
     $this->_doFileTest(InstanceStorage::getStorageMount($_instance), $_testFile, $_contents, static::INSTANCE_STORAGE_PATH);
     $this->_doFileTest(InstanceStorage::getPrivateStorageMount($_instance), $_testFile, $_contents, static::INSTANCE_PRIVATE_PATH);
     $this->_doFileTest(InstanceStorage::getOwnerPrivateStorageMount($_instance), $_testFile, $_contents, static::OWNER_PRIVATE_PATH);
     $this->_doFileTest(InstanceStorage::getSnapshotMount($_instance), $_testFile, $_contents, static::SNAPSHOT_PATH);
 }
コード例 #2
0
 /**
  * @param ProvisionServiceRequest $request
  *
  * @return \DreamFactory\Enterprise\Common\Provisioners\BaseResponse|void
  * @throws \Exception
  */
 protected function doProvision($request)
 {
     //  Wipe existing stuff
     $_instance = $request->getInstance();
     $_filesystem = $request->getStorage();
     $_paths = [];
     //******************************************************************************
     //* Directories are all relative to the request's storage file system
     //******************************************************************************
     //  The instance's base storage path
     $_instanceRootPath = trim($_instance->instance_id_text);
     //  The user's and instance's private path
     $_privateName = InstanceStorage::getPrivatePathName();
     $_ownerPrivatePath = $_privateName;
     $_privatePath = Disk::segment([$_instanceRootPath, $_privateName]);
     //  Make sure everything exists
     try {
         !$_filesystem->has($_privatePath) && $_filesystem->createDir($_privatePath);
         !$_filesystem->has($_ownerPrivatePath) && $_filesystem->createDir($_ownerPrivatePath);
         //  Now ancillary sub-directories
         foreach (config('provisioning.public-paths', []) as $_path) {
             $_paths[] = Disk::segment([$_instanceRootPath, $_path]);
         }
         foreach (config('provisioning.private-paths', []) as $_path) {
             $_paths[] = Disk::segment([$_privatePath, $_path]);
         }
         foreach (config('provisioning.owner-private-paths', []) as $_path) {
             $_paths[] = Disk::segment([$_ownerPrivatePath, $_path]);
         }
         foreach ($_paths as $_path) {
             !$_filesystem->has($_path) && $_filesystem->createDir($_path);
         }
         $this->debug('[provisioning:storage] structure built', $_paths);
     } catch (\Exception $_ex) {
         $this->error('[provisioning:storage] error creating directory structure: ' . $_ex->getMessage());
         throw $_ex;
     }
     //  Fire off a "storage.provisioned" event...
     \Event::fire('dfe.storage.provisioned', [$this, $request]);
     $this->info('[provisioning:storage] instance "' . $_instance->instance_id_text . '" complete');
     $this->privatePath = $_privatePath;
     $this->ownerPrivatePath = $_ownerPrivatePath;
 }
コード例 #3
0
 /**
  * @param bool $createIfNull
  *
  * @return Filesystem
  */
 public function getStorage($createIfNull = true)
 {
     //  Use requested file system if one...
     if (null === ($_storage = $this->get('storage')) && $createIfNull) {
         $_instance = $this->getInstance();
         $_user = $_instance->user;
         if (empty($_user)) {
             try {
                 $_user = User::findOrFail($_instance->user_id);
             } catch (ModelNotFoundException $_ex) {
                 \Log::error('Attempt to create an instance for a non-existent user_id: ' . $_instance->user_id);
                 throw new \RuntimeException('Invalid user assigned to instance.');
             }
         }
         InstanceStorage::buildStorageMap($_user->storage_id_text);
         $_storage = $_instance->getStorageRootMount();
         $this->setStorage($_storage);
     }
     return $_storage;
 }
コード例 #4
0
 /**
  * Moves a file from somewhere to the expired trash heap
  *
  * @param Filesystem $filesystem
  * @param string     $filename
  * @param array      $config An optional configuration array
  *
  * @return bool
  */
 protected function moveToTrash(Filesystem $filesystem, $filename, array $config = [])
 {
     if (config('snapshot.soft-delete', EnterpriseDefaults::SNAPSHOT_SOFT_DELETE)) {
         $_trash = InstanceStorage::getTrashMount('expired');
         if ($_trash->writeStream($filename, $filesystem->readStream($filename), $config)) {
             return $filesystem->delete($filename);
         }
         //  Try and remove any partial file created before failure
         try {
             $_trash->delete($filename);
         } catch (\Exception $_ex) {
             //  Ignored, this is a cleanup in case of failure...
         }
     } else {
         try {
             if ($filesystem->has($filename)) {
                 return $filesystem->delete($filename);
             }
             //  It's gone
             return true;
         } catch (\Exception $_ex) {
             //  Can't delete? not good
             return false;
         }
     }
     return false;
 }
コード例 #5
0
 /**
  * Create capsule symlinks
  *
  * @param string $source      The instance source
  * @param string $destination The destination
  * @param string $storage     The storage path to link
  *
  * @return bool
  */
 protected function createCapsuleLinks($source, $destination, $storage)
 {
     $_links = config('capsule.instance.symlinks', []);
     //  Create symlinks
     foreach ($_links as $_link) {
         $_linkTarget = 'storage' == $_link ? Disk::path([$storage, InstanceStorage::getStoragePath($this->instance)]) : Disk::path([$source, $_link]);
         $_linkName = Disk::path([$destination, $_link]);
         if (!file_exists($_linkName) || $_linkTarget != readlink($_linkName)) {
             if (false === symlink($_linkTarget, $_linkName)) {
                 $this->error('Error symlinking target "' . $_linkTarget . '"');
                 return false;
             }
         }
     }
     //  Create the bootstrap[/cache] directory
     $_sourcePath = Disk::path([$source, 'bootstrap']);
     $_bootstrapPath = Disk::path([$destination, 'bootstrap'], true);
     //  Ensure the cache directory is there as well...
     Disk::path([$_bootstrapPath, 'cache'], true);
     $_files = Disk::glob($_sourcePath . DIRECTORY_SEPARATOR . '*', GlobFlags::GLOB_NODIR | GlobFlags::GLOB_NODOTS);
     foreach ($_files as $_file) {
         if (false === copy($_sourcePath . DIRECTORY_SEPARATOR . $_file, $_bootstrapPath . DIRECTORY_SEPARATOR . $_file)) {
             $this->error('Failure copying bootstrap file "' . $_file . '" to "' . $_bootstrapPath . '"');
             return false;
         }
     }
     return true;
 }
コード例 #6
0
ファイル: Instance.php プロジェクト: pkdevboxy/dfe-database
 /**
  * Build the 'paths' section of the metadata
  *
  * @param \DreamFactory\Enterprise\Database\Models\Instance $instance
  *
  * @return array
  */
 protected static function buildPathMetadata(Instance $instance)
 {
     return ['storage-root' => InstanceStorage::getStorageRootPath(), 'storage-path' => $instance->getStoragePath(), 'private-path' => $instance->getPrivatePath(), 'owner-private-path' => $instance->getOwnerPrivatePath(), 'snapshot-path' => $instance->getSnapshotPath(), 'trash-path' => $instance->getTrashPath()];
 }
コード例 #7
0
ファイル: User.php プロジェクト: pkdevboxy/dfe-database
 /**
  * @param string|array|null $append
  * @param bool|true         $create
  * @param int               $mode
  * @param bool|true         $recursive
  *
  * @return string
  */
 public function getOwnerPrivatePath($append = null, $create = true, $mode = 0777, $recursive = true)
 {
     InstanceStorage::buildStorageMap($this->storage_id_text);
     return Disk::path([config('provisioning.storage-root', EnterpriseDefaults::STORAGE_ROOT), InstanceStorage::getStorageRootPath(), InstanceStorage::getPrivatePathName(), $append], $create, $mode, $recursive);
 }