Esempio n. 1
0
 /**
  * @param \OC\Files\Storage\Shared $storage
  * @param IStorage $sourceStorage
  * @param ICacheEntry $sourceRootInfo
  */
 public function __construct($storage, IStorage $sourceStorage, ICacheEntry $sourceRootInfo)
 {
     $this->storage = $storage;
     $this->sourceStorage = $sourceStorage;
     $this->sourceRootInfo = $sourceRootInfo;
     $this->sourceCache = $sourceStorage->getCache();
     parent::__construct($this->sourceCache, $this->sourceRootInfo->getPath());
 }
Esempio n. 2
0
 private function init()
 {
     if ($this->initialized) {
         return;
     }
     $this->initialized = true;
     Filesystem::initMountPoints($this->share['uid_owner']);
     $sourcePath = $this->ownerView->getPath($this->share['file_source']);
     list($this->sourceStorage, $sourceInternalPath) = $this->ownerView->resolvePath($sourcePath);
     $this->sourceRootInfo = $this->sourceStorage->getCache()->get($sourceInternalPath);
 }
Esempio n. 3
0
 public function testBatchedPropagation()
 {
     $this->storage->mkdir('foo/baz');
     $this->storage->mkdir('asd');
     $this->storage->file_put_contents('asd/file.txt', 'bar');
     $this->storage->file_put_contents('foo/baz/file.txt', 'bar');
     $this->storage->getScanner()->scan('');
     $paths = ['', 'foo', 'foo/bar', 'asd', 'foo/baz'];
     $oldInfos = $this->getFileInfos($paths);
     $propagator = $this->storage->getPropagator();
     $propagator->beginBatch();
     $propagator->propagateChange('asd/file.txt', time(), 10);
     $propagator->propagateChange('foo/bar/file.txt', time(), 2);
     $newInfos = $this->getFileInfos($paths);
     // no changes until we finish the batch
     foreach ($oldInfos as $i => $oldInfo) {
         $this->assertEquals($oldInfo->getSize(), $newInfos[$i]->getSize());
         $this->assertEquals($oldInfo->getEtag(), $newInfos[$i]->getEtag());
         $this->assertEquals($oldInfo->getMTime(), $newInfos[$i]->getMTime());
     }
     $propagator->commitBatch();
     $newInfos = $this->getFileInfos($paths);
     foreach ($oldInfos as $i => $oldInfo) {
         if ($oldInfo->getPath() !== 'foo/baz') {
             $this->assertNotEquals($oldInfo->getEtag(), $newInfos[$i]->getEtag());
         }
     }
     $this->assertEquals($oldInfos['']->getSize() + 12, $newInfos['']->getSize());
     $this->assertEquals($oldInfos['asd']->getSize() + 10, $newInfos['asd']->getSize());
     $this->assertEquals($oldInfos['foo']->getSize() + 2, $newInfos['foo']->getSize());
     $this->assertEquals($oldInfos['foo/bar']->getSize() + 2, $newInfos['foo/bar']->getSize());
     $this->assertEquals($oldInfos['foo/baz']->getSize(), $newInfos['foo/baz']->getSize());
 }
Esempio n. 4
0
 private function init()
 {
     if ($this->initialized) {
         return;
     }
     $this->initialized = true;
     try {
         Filesystem::initMountPoints($this->superShare->getShareOwner());
         $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId());
         list($this->sourceStorage, $sourceInternalPath) = $this->ownerView->resolvePath($sourcePath);
         $this->sourceRootInfo = $this->sourceStorage->getCache()->get($sourceInternalPath);
     } catch (\Exception $e) {
         $this->logger->logException($e);
     }
 }
Esempio n. 5
0
 /**
  * Rename a file or folder in the cache and update the size, etag and mtime of the parent folders
  *
  * @param IStorage $sourceStorage
  * @param string $source
  * @param string $target
  */
 public function renameFromStorage(IStorage $sourceStorage, $source, $target)
 {
     if (!$this->enabled or Scanner::isPartialFile($source) or Scanner::isPartialFile($target)) {
         return;
     }
     $time = time();
     $sourceCache = $sourceStorage->getCache();
     $sourceUpdater = $sourceStorage->getUpdater();
     $sourcePropagator = $sourceStorage->getPropagator();
     if ($sourceCache->inCache($source)) {
         if ($this->cache->inCache($target)) {
             $this->cache->remove($target);
         }
         if ($sourceStorage === $this->storage) {
             $this->cache->move($source, $target);
         } else {
             $this->cache->moveFromCache($sourceCache, $source, $target);
         }
     }
     if (pathinfo($source, PATHINFO_EXTENSION) !== pathinfo($target, PATHINFO_EXTENSION)) {
         // handle mime type change
         $mimeType = $this->storage->getMimeType($target);
         $fileId = $this->cache->getId($target);
         $this->cache->update($fileId, ['mimetype' => $mimeType]);
     }
     if ($sourceCache instanceof Cache) {
         $sourceCache->correctFolderSize($source);
     }
     if ($this->cache instanceof Cache) {
         $this->cache->correctFolderSize($target);
     }
     if ($sourceUpdater instanceof Updater) {
         $sourceUpdater->correctParentStorageMtime($source);
     }
     $this->correctParentStorageMtime($target);
     $this->updateStorageMTimeOnly($target);
     $sourcePropagator->propagateChange($source, $time);
     $this->propagator->propagateChange($target, $time);
 }
Esempio n. 6
0
 private function triggerPropagator(IStorage $storage, $internalPath)
 {
     $storage->getPropagator()->propagateChange($internalPath, time());
 }