Example #1
0
 /**
  * check if a file or folder has been updated since $time
  *
  * @param string $path
  * @param int $time
  * @throws \OCP\Files\StorageNotAvailableException
  * @return bool
  */
 public function hasUpdated($path, $time)
 {
     $this->init();
     $path = $this->cleanPath($path);
     try {
         // force refresh for $path
         $this->statCache->remove($path);
         $response = $this->propfind($path);
         if (isset($response['{DAV:}getetag'])) {
             $cachedData = $this->getCache()->get($path);
             $etag = null;
             if (isset($response['{DAV:}getetag'])) {
                 $etag = trim($response['{DAV:}getetag'], '"');
             }
             if (!empty($etag) && $cachedData['etag'] !== $etag) {
                 return true;
             } else {
                 if (isset($response['{http://open-collaboration-services.org/ns}share-permissions'])) {
                     $sharePermissions = (int) $response['{http://open-collaboration-services.org/ns}share-permissions'];
                     return $sharePermissions !== $cachedData['permissions'];
                 } else {
                     if (isset($response['{http://owncloud.org/ns}permissions'])) {
                         $permissions = $this->parsePermissions($response['{http://owncloud.org/ns}permissions']);
                         return $permissions !== $cachedData['permissions'];
                     } else {
                         return false;
                     }
                 }
             }
         } else {
             $remoteMtime = strtotime($response['{DAV:}getlastmodified']);
             return $remoteMtime > $time;
         }
     } catch (ClientHttpException $e) {
         if ($e->getHttpStatus() === 404 || $e->getHttpStatus() === 405) {
             if ($path === '') {
                 // if root is gone it means the storage is not available
                 throw new StorageNotAvailableException(get_class($e) . ': ' . $e->getMessage());
             }
             return false;
         }
         $this->convertException($e, $path);
         return false;
     } catch (\Exception $e) {
         $this->convertException($e, $path);
         return false;
     }
 }
Example #2
0
 /**
  * check if a file or folder has been updated since $time
  *
  * @param string $path
  * @param int $time
  * @throws \OCP\Files\StorageNotAvailableException
  * @return bool
  */
 public function hasUpdated($path, $time)
 {
     $this->init();
     $path = $this->cleanPath($path);
     try {
         // force refresh for $path
         $this->statCache->remove($path);
         $response = $this->propfind($path);
         if (isset($response['{DAV:}getetag'])) {
             $cachedData = $this->getCache()->get($path);
             $etag = null;
             if (isset($response['{DAV:}getetag'])) {
                 $etag = trim($response['{DAV:}getetag'], '"');
             }
             if (!empty($etag) && $cachedData['etag'] !== $etag) {
                 return true;
             } else {
                 if (isset($response['{http://owncloud.org/ns}permissions'])) {
                     $permissions = $this->parsePermissions($response['{http://owncloud.org/ns}permissions']);
                     return $permissions !== $cachedData['permissions'];
                 } else {
                     return false;
                 }
             }
         } else {
             $remoteMtime = strtotime($response['{DAV:}getlastmodified']);
             return $remoteMtime > $time;
         }
     } catch (ClientHttpException $e) {
         if ($e->getHttpStatus() === 404) {
             return false;
         }
         $this->convertException($e);
         return false;
     } catch (\Exception $e) {
         $this->convertException($e);
         return false;
     }
 }
Example #3
0
 /**
  * copy file between two storages
  *
  * @param Storage $sourceStorage
  * @param string $sourceInternalPath
  * @param string $targetInternalPath
  * @param bool $preserveMtime
  * @param bool $isRename
  * @return bool
  * @throws \Exception
  */
 private function copyBetweenStorage(Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime, $isRename)
 {
     // for versions we have nothing to do, because versions should always use the
     // key from the original file. Just create a 1:1 copy and done
     if ($this->isVersion($targetInternalPath) || $this->isVersion($sourceInternalPath)) {
         // remember that we try to create a version so that we can detect it during
         // fopen($sourceInternalPath) and by-pass the encryption in order to
         // create a 1:1 copy of the file
         $this->arrayCache->set('encryption_copy_version_' . $sourceInternalPath, true);
         $result = $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
         $this->arrayCache->remove('encryption_copy_version_' . $sourceInternalPath);
         if ($result) {
             $info = $this->getCache('', $sourceStorage)->get($sourceInternalPath);
             // make sure that we update the unencrypted size for the version
             if (isset($info['encrypted']) && $info['encrypted'] === true) {
                 $this->updateUnencryptedSize($this->getFullPath($targetInternalPath), $info['size']);
             }
             $this->updateEncryptedVersion($sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename);
         }
         return $result;
     }
     // first copy the keys that we reuse the existing file key on the target location
     // and don't create a new one which would break versions for example.
     $mount = $this->mountManager->findByStorageId($sourceStorage->getId());
     if (count($mount) === 1) {
         $mountPoint = $mount[0]->getMountPoint();
         $source = $mountPoint . '/' . $sourceInternalPath;
         $target = $this->getFullPath($targetInternalPath);
         $this->copyKeys($source, $target);
     } else {
         $this->logger->error('Could not find mount point, can\'t keep encryption keys');
     }
     if ($sourceStorage->is_dir($sourceInternalPath)) {
         $dh = $sourceStorage->opendir($sourceInternalPath);
         $result = $this->mkdir($targetInternalPath);
         if (is_resource($dh)) {
             while ($result and ($file = readdir($dh)) !== false) {
                 if (!Filesystem::isIgnoredDir($file)) {
                     $result &= $this->copyFromStorage($sourceStorage, $sourceInternalPath . '/' . $file, $targetInternalPath . '/' . $file, false, $isRename);
                 }
             }
         }
     } else {
         try {
             $source = $sourceStorage->fopen($sourceInternalPath, 'r');
             $target = $this->fopen($targetInternalPath, 'w');
             list(, $result) = \OC_Helper::streamCopy($source, $target);
             fclose($source);
             fclose($target);
         } catch (\Exception $e) {
             fclose($source);
             fclose($target);
             throw $e;
         }
         if ($result) {
             if ($preserveMtime) {
                 $this->touch($targetInternalPath, $sourceStorage->filemtime($sourceInternalPath));
             }
             $this->updateEncryptedVersion($sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename);
         } else {
             // delete partially written target file
             $this->unlink($targetInternalPath);
             // delete cache entry that was created by fopen
             $this->getCache()->remove($targetInternalPath);
         }
     }
     return (bool) $result;
 }