Пример #1
0
 /**
  * @dataProvider filesystemProvider
  */
 public function testWrite(Filesystem $filesystem, $adapter, $cache)
 {
     $this->assertTrue($filesystem->write('some_file.txt', 'some content'));
     $this->assertTrue($filesystem->has('some_file.txt'));
     $this->assertTrue($cache->has('some_file.txt'));
     $this->assertTrue($adapter->has('some_file.txt'));
     $this->assertCount(1, $filesystem->listContents());
     $this->assertCount(1, $cache->listContents('', false));
     $this->assertCount(1, $adapter->listContents('', false));
     $filesystem->rename('some_file.txt', 'other_name.txt');
     $this->assertFalse($filesystem->has('some_file.txt'));
     $this->assertFalse($cache->has('some_file.txt'));
     $this->assertFalse($adapter->has('some_file.txt'));
     $this->assertTrue($filesystem->has('other_name.txt'));
     $this->assertTrue($cache->has('other_name.txt'));
     $this->assertTrue($adapter->has('other_name.txt'));
     $this->assertCount(1, $filesystem->listContents());
     $this->assertCount(1, $cache->listContents('', false));
     $this->assertCount(1, $adapter->listContents('', false));
     $filesystem->delete('other_name.txt');
     $this->assertFalse($filesystem->has('other_name.txt'));
     $this->assertFalse($cache->has('other_name.txt'));
     $this->assertFalse($adapter->has('other_name.txt'));
     $this->assertCount(0, $filesystem->listContents());
     $this->assertCount(0, $cache->listContents('', false));
     $this->assertCount(0, $adapter->listContents('', false));
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function rename($source, $target)
 {
     if ($this->file_exists($target)) {
         $this->unlink($target);
     }
     return $this->flysystem->rename($this->buildPath($source), $this->buildPath($target));
 }
Пример #3
0
 /**
  * @inheritdoc
  */
 protected function _move($source, $target, $name)
 {
     $path = $this->_joinPath($target, $name);
     if ($this->fs->rename($source, $path)) {
         return $path;
     }
     return false;
 }
 /**
  * @param $sourceFile
  * @param $repoFile
  *
  * @return bool
  *
  */
 public function moveToRepo($sourceFile, $repoFile)
 {
     $filesystem = new Filesystem(new Adapter('/'));
     if ($filesystem->has($repoFile)) {
         $filesystem->delete($repoFile);
     }
     $result = $filesystem->rename($sourceFile, $repoFile);
     unset($filesystem);
     return $result;
 }
Пример #5
0
 public function testRename()
 {
     $old = 'old.txt';
     $new = 'new.txt';
     $this->prophecy->has($old)->willReturn(true);
     $this->prophecy->has($new)->willReturn(false);
     $this->prophecy->rename($old, $new)->willReturn(true);
     $response = $this->filesystem->rename($old, $new);
     $this->assertTrue($response);
 }
Пример #6
0
 /**
  * @inheritdoc
  */
 public function rename($path, $newPath)
 {
     $innerPath = $this->getInnerPath($path);
     $newInnerPath = $this->getInnerPath($newPath);
     try {
         $return = $this->fileSystem->rename($innerPath, $newInnerPath);
     } catch (FileNotFoundException $e) {
         throw $this->exceptionWrapper($e, $path);
     } catch (FileExistsException $e) {
         throw $this->exceptionWrapper($e, $path);
     }
     if ($return !== false) {
         $this->invokePlugin("addPathToIndex", [$newPath, $newInnerPath], $this);
         $this->invokePlugin("removePathFromIndex", [$path, $innerPath], $this);
     }
     return $return;
 }
Пример #7
0
 /**
  * Rename lessons, adding 0 padding to the number.
  */
 public function renameLessonsWithRightPadding()
 {
     $list = $this->system->listContents(LESSONS_FOLDER);
     foreach ($list as $entry) {
         if ($entry['type'] != 'file') {
             continue;
         }
         $originalName = $entry['basename'];
         $oldNumber = substr($originalName, 0, strpos($originalName, '-'));
         if (strlen($oldNumber) == 4) {
             continue;
         }
         // already correct
         $newNumber = sprintf("%04d", $oldNumber);
         $nameWithoutNumber = substr($originalName, strpos($originalName, '-') + 1);
         $newName = $newNumber . '-' . $nameWithoutNumber;
         $this->system->rename(LESSONS_FOLDER . '/' . $originalName, LESSONS_FOLDER . '/' . $newName);
     }
 }
Пример #8
0
 /**
  * @param File[] $files
  *
  * @throws CanNotSavedException
  *
  * @return File[]
  */
 public function save($files)
 {
     $fileSystemAdapter = $this->getAdapter();
     $fileSystem = new Filesystem($fileSystemAdapter);
     $savedFiles = [];
     $i = 0;
     foreach ($files as $file) {
         $i++;
         $filePath = $this->fileNameResolver->resolve(new \DateTime('now', new \DateTimeZone('UTC')), 'database', $file->getExtension());
         $newBackupLocation = $this->backupFolder . '/' . $filePath;
         $currBackupLocation = $file->getPath();
         if ($fileSystem->has($newBackupLocation)) {
             $fileSystem->delete($newBackupLocation);
         }
         if (!$fileSystem->rename($currBackupLocation, $newBackupLocation)) {
             throw new CanNotSavedException();
         }
         $savedFiles[] = new File($fileSystemAdapter->applyPathPrefix($newBackupLocation));
     }
     return $savedFiles;
 }
 public function assembleChunks($chunks, $removeChunk, $renameChunk)
 {
     // the index is only added to be in sync with the filesystem storage
     $path = $this->prefix . '/' . $this->unhandledChunk['uuid'] . '/';
     $filename = $this->unhandledChunk['index'] . '_' . $this->unhandledChunk['original'];
     if (empty($chunks)) {
         $target = $filename;
     } else {
         sort($chunks, SORT_STRING | SORT_FLAG_CASE);
         $target = pathinfo($chunks[0], PATHINFO_BASENAME);
     }
     if ($this->unhandledChunk['index'] === 0) {
         // if it's the first chunk overwrite the already existing part
         // to avoid appending to earlier failed uploads
         $handle = fopen($path . '/' . $target, 'w');
     } else {
         $handle = fopen($path . '/' . $target, 'a');
     }
     $this->filesystem->putStream($path . $target, $handle);
     if ($renameChunk) {
         $name = preg_replace('/^(\\d+)_/', '', $target);
         /* The name can only match if the same user in the same session is
          * trying to upload a file under the same name AND the previous upload failed,
          * somewhere between this function, and the cleanup call. If that happened
          * the previous file is unaccessible by the user, but if it is not removed
          * it will block the user from trying to re-upload it.
          */
         if ($this->filesystem->has($path . $name)) {
             $this->filesystem->delete($path . $name);
         }
         $this->filesystem->rename($path . $target, $path . $name);
         $target = $name;
     }
     $uploaded = $this->filesystem->get($path . $target);
     if (!$renameChunk) {
         return $uploaded;
     }
     return new FlysystemFile($uploaded, $this->filesystem, $this->streamWrapperPrefix);
 }
Пример #10
0
 /**
  * Renames the object for a given path.
  *
  * @param string $path
  * @param string $newpath
  *
  * @return bool `true` on success, `false` on failure.
  */
 public function rename($path, $newpath)
 {
     $baseAdapter = $this->getBaseAdapter();
     if ($baseAdapter instanceof EmulateRenameDirectoryInterface && $this->hasDirectory($path)) {
         return $baseAdapter->renameDirectory($path, $newpath);
     }
     return parent::rename($path, $newpath);
 }
Пример #11
0
 /**
  * Move a file to a new location.
  *
  * @param  string  $from
  * @param  string  $to
  * @return bool
  */
 public function move($from, $to)
 {
     return parent::rename($from, $to);
 }
Пример #12
0
 /**
  * @param string $path
  * @param string $newPath
  *
  * @return bool
  */
 public function rename($path, $newPath)
 {
     return $this->filesystem->rename($path, $newPath);
 }
 /**
  * 3.txt
  * 2.txt.
  */
 public function testRename()
 {
     $this->assertTrue($this->filesystem->rename('1.txt', '3.txt'));
     $this->assertFalse($this->filesystem->has('1.txt'));
     $this->assertTrue($this->filesystem->has('3.txt'));
 }
 /**
  * @param Payload $payload
  * @param Messenger $messenger
  * @return PromiseInterface
  */
 public function rename(Payload $payload, Messenger $messenger)
 {
     return \React\Promise\resolve(['renamed' => $this->flysystem->rename($payload['from'], $payload['to'])]);
 }
Пример #15
0
 /**
  * @inheritdoc
  */
 public function rename($path, $newpath)
 {
     try {
         return parent::rename($path, $newpath);
     } catch (\Exception $e) {
         $this->errors[] = $e->getMessage();
     }
     return false;
 }