public function __construct()
 {
     $this->view = new \OC\Files\View();
     $this->view->getUpdater()->disable();
     $this->public_share_key_id = Helper::getPublicShareKeyId();
     $this->recovery_key_id = Helper::getRecoveryKeyId();
 }
Example #2
0
 /**
  * @param IConfig $config
  * @param View $view
  * @param Connection $connection
  */
 public function __construct(IConfig $config, View $view, Connection $connection)
 {
     $this->view = $view;
     $this->view->getUpdater()->disable();
     $this->connection = $connection;
     $this->moduleId = \OCA\Encryption\Crypto\Encryption::ID;
     $this->config = $config;
 }
Example #3
0
 /**
  * @param IConfig $config
  * @param View $view
  * @param Connection $connection
  * @param ILogger $logger
  */
 public function __construct(IConfig $config, View $view, Connection $connection, ILogger $logger)
 {
     $this->view = $view;
     $this->view->getUpdater()->disable();
     $this->connection = $connection;
     $this->moduleId = \OCA\Encryption\Crypto\Encryption::ID;
     $this->config = $config;
     $this->logger = $logger;
     $this->installedVersion = $this->config->getAppValue('files_encryption', 'installed_version', '-1');
 }
Example #4
0
 /**
  * @param string $user
  * @return \OC\Files\Cache\ChangePropagator
  */
 public function getChangePropagator($user)
 {
     $activeUser = $this->userSession->getUser();
     // for the local user we want to propagator from the active view, not any cached one
     if ($activeUser && $activeUser->getUID() === $user && Filesystem::getView() instanceof View) {
         // it's important that we take the existing propagator here to make sure we can listen to external changes
         $this->changePropagators[$user] = Filesystem::getView()->getUpdater()->getPropagator();
     }
     if (isset($this->changePropagators[$user])) {
         return $this->changePropagators[$user];
     }
     $view = new View('/' . $user . '/files');
     $this->changePropagators[$user] = $view->getUpdater()->getPropagator();
     return $this->changePropagators[$user];
 }
Example #5
0
 /**
  * Copy a file or folder on storage level
  *
  * @param View $view
  * @param string $source
  * @param string $target
  * @return bool
  */
 private static function copy(View $view, $source, $target)
 {
     /** @var \OC\Files\Storage\Storage $sourceStorage */
     list($sourceStorage, $sourceInternalPath) = $view->resolvePath($source);
     /** @var \OC\Files\Storage\Storage $targetStorage */
     list($targetStorage, $targetInternalPath) = $view->resolvePath($target);
     /** @var \OC\Files\Storage\Storage $ownerTrashStorage */
     $result = $targetStorage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
     if ($result) {
         $view->getUpdater()->update($target);
     }
     return $result;
 }
Example #6
0
 /**
  * move file to the trash bin
  *
  * @param string $file_path path to the deleted file/directory relative to the files root directory
  */
 public static function move2trash($file_path)
 {
     // get the user for which the filesystem is setup
     $root = Filesystem::getRoot();
     list(, $user) = explode('/', $root);
     $size = 0;
     list($owner, $ownerPath) = self::getUidAndFilename($file_path);
     $view = new \OC\Files\View('/' . $user);
     // file has been deleted in between
     if (!$view->file_exists('/files/' . $file_path)) {
         return true;
     }
     self::setUpTrash($user);
     if ($owner !== $user) {
         // also setup for owner
         self::setUpTrash($owner);
     }
     $path_parts = pathinfo($file_path);
     $filename = $path_parts['basename'];
     $location = $path_parts['dirname'];
     $timestamp = time();
     $userTrashSize = self::getTrashbinSize($user);
     // disable proxy to prevent recursive calls
     $trashPath = '/files_trashbin/files/' . $filename . '.d' . $timestamp;
     /** @var \OC\Files\Storage\Storage $trashStorage */
     list($trashStorage, $trashInternalPath) = $view->resolvePath($trashPath);
     /** @var \OC\Files\Storage\Storage $sourceStorage */
     list($sourceStorage, $sourceInternalPath) = $view->resolvePath('/files/' . $file_path);
     try {
         $sizeOfAddedFiles = $sourceStorage->filesize($sourceInternalPath);
         if ($trashStorage->file_exists($trashInternalPath)) {
             $trashStorage->unlink($trashInternalPath);
         }
         $trashStorage->moveFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
     } catch (\OCA\Files_Trashbin\Exceptions\CopyRecursiveException $e) {
         $sizeOfAddedFiles = false;
         if ($trashStorage->file_exists($trashInternalPath)) {
             $trashStorage->unlink($trashInternalPath);
         }
         \OCP\Util::writeLog('files_trashbin', 'Couldn\'t move ' . $file_path . ' to the trash bin', \OC_log::ERROR);
     }
     if ($sourceStorage->file_exists($sourceInternalPath)) {
         // failed to delete the original file, abort
         $sourceStorage->unlink($sourceInternalPath);
         return false;
     }
     $view->getUpdater()->rename('/files/' . $file_path, $trashPath);
     if ($sizeOfAddedFiles !== false) {
         $size = $sizeOfAddedFiles;
         $query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)");
         $result = $query->execute(array($filename, $timestamp, $location, $user));
         if (!$result) {
             \OCP\Util::writeLog('files_trashbin', 'trash bin database couldn\'t be updated', \OC_log::ERROR);
         }
         \OCP\Util::emitHook('\\OCA\\Files_Trashbin\\Trashbin', 'post_moveToTrash', array('filePath' => \OC\Files\Filesystem::normalizePath($file_path), 'trashPath' => \OC\Files\Filesystem::normalizePath($filename . '.d' . $timestamp)));
         $size += self::retainVersions($file_path, $filename, $owner, $ownerPath, $timestamp);
         // if owner !== user we need to also add a copy to the owners trash
         if ($user !== $owner) {
             self::copyFilesToOwner($file_path, $owner, $ownerPath, $timestamp);
         }
     }
     $userTrashSize += $size;
     self::scheduleExpire($userTrashSize, $user);
     // if owner !== user we also need to update the owners trash size
     if ($owner !== $user) {
         $ownerTrashSize = self::getTrashbinSize($owner);
         $ownerTrashSize += $size;
         self::scheduleExpire($ownerTrashSize, $owner);
     }
     return $sizeOfAddedFiles === false ? false : true;
 }