Esempio n. 1
0
 /**
  * Copy file.
  *
  * @param string $filePath File path
  * @param File   $file     File object
  *
  * @throws FileExistsException
  *
  * @return bool True on success, false on failure.
  */
 public function copyFile($filePath, File $file)
 {
     try {
         return $this->filesystem->copy($filePath, $file->getDirectories() . DIRECTORY_SEPARATOR . $file->getFileName());
     } catch (FlysystemFileExistsException $e) {
         FileExistsException::fileExists();
     }
 }
Esempio n. 2
0
 /**
  * Duplicate a file given it's URL
  *
  * @param  string $url
  * @return string
  */
 public function duplicate($url)
 {
     // Make the destination path
     $current_path = $this->helpers->path($url);
     $filename = basename($current_path);
     $dst_disk = $this->disks ? $this->disks->getFilesystem('dst') : $this->disk;
     $new_path = $this->storage->makeNestedAndUniquePath($filename, $dst_disk);
     // Copy, supporting alternative destination disks
     if ($this->disks) {
         $this->disks->copy('src://' . $current_path, 'dst://' . $new_path);
     } else {
         $this->disk->copy($current_path, $new_path);
     }
     // Return the Upchuck URL
     return $this->helpers->url($new_path);
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function copy($source, $target)
 {
     if ($this->file_exists($target)) {
         $this->unlink($target);
     }
     return $this->flysystem->copy($this->buildPath($source), $this->buildPath($target));
 }
Esempio n. 4
0
 public function testCopy()
 {
     $old = 'old.txt';
     $new = 'new.txt';
     $this->prophecy->has($old)->willReturn(true);
     $this->prophecy->has($new)->willReturn(false);
     $this->prophecy->copy($old, $new)->willReturn(true);
     $response = $this->filesystem->copy($old, $new);
     $this->assertTrue($response);
 }
Esempio n. 5
0
 /**
  * @inheritdoc
  */
 public function copy($path, $newPath)
 {
     $innerPath = $this->getInnerPath($path);
     $newInnerPath = $this->getInnerPath($newPath);
     try {
         $return = $this->fileSystem->copy($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);
     }
     return $return;
 }
Esempio n. 6
0
 public function testCopyFail()
 {
     $mock = Mockery::mock('League\\Flysystem\\AdapterInterface');
     $mock->shouldReceive('write')->andReturn(array('path' => 'path.txt'));
     $mock->shouldReceive('copy')->andReturn(false);
     $mock->shouldReceive('has')->with('path.txt')->andReturn(false, true);
     $mock->shouldReceive('has')->with('new.txt')->andReturn(false);
     $filesystem = new Filesystem($mock);
     $filesystem->write('path.txt', 'content');
     $this->assertFalse($filesystem->copy('path.txt', 'new.txt'));
 }
Esempio n. 7
0
 /**
  * Copy a file.
  *
  * @param string $path    Path to the existing file.
  * @param string $newpath The new path of the file.
  *
  * @throws FileExistsException   Thrown if $newpath exists.
  * @throws FileNotFoundException Thrown if $path does not exist.
  *
  * @return bool True on success, false on failure.
  */
 public function copy($path, $newpath)
 {
     $result = parent::copy($path, $newpath);
     if ($result && ($resource = $this->get($newpath))) {
         return $this->dispatch(new SyncFile($resource));
     }
     return $result;
 }
 /**
  * Copies the App routes into their defined location in atuin directory.
  * 
  */
 protected function upRoutes()
 {
     $basePath = dirname(Yii::$app->getVendorPath());
     $filesystem = new Filesystem(new Adapter($basePath));
     // 1 - Move the routes into the route system in case we have those files
     $fileHelper = new yii\helpers\FileHelper();
     foreach ($this->arrRoutes as $type) {
         $path = $this->module->basePath . '/routes/' . $type . '/';
         if (is_dir($path)) {
             $files = $fileHelper->findFiles($path, ['only' => ['*.php'], 'recursive' => FALSE]);
             foreach ($files as $file) {
                 $fileName = str_replace($path, '', $file);
                 $from = str_replace($basePath, '', $file);
                 $to = '/atuin/routes/' . $type . '/app_' . $this->module->id . '_' . $fileName;
                 if (!$filesystem->has($to)) {
                     $filesystem->copy($from, $to);
                 }
             }
         }
     }
 }
 /**
  * 3.txt
  * 2.txt
  * test/1.txt.
  */
 public function testCreateDir()
 {
     $this->assertTrue($this->filesystem->createDir('test'));
     $this->assertTrue($this->filesystem->copy('2.txt', 'test/1.txt'));
 }
Esempio n. 10
0
 /**
  * @inheritdoc
  */
 protected function _copy($source, $target, $name)
 {
     return $this->fs->copy($source, $this->_joinPath($target, $name));
 }
Esempio n. 11
0
 /**
  * Copy a file
  *
  * @param   string $path
  * @param   string $newpath
  * @return  boolean
  */
 public function copy($path, $newpath)
 {
     try {
         return parent::copy($path, $newpath);
     } catch (\Exception $e) {
         $this->errors[] = $e->getMessage();
     }
     return false;
 }