/** * @dataProvider adapterProvider */ public function testUpdate(FilesystemInterface $filesystem, $adapter, $mock) { $mock->shouldReceive('put')->andReturn(true, false); $mock->shouldReceive('stat')->andReturn(['type' => NET_SFTP_TYPE_DIRECTORY, 'mtime' => time(), 'size' => 20, 'permissions' => 0777]); $this->assertTrue($filesystem->update('something', 'something')); $this->assertFalse($filesystem->update('something_else.txt', 'else')); }
/** * Write settings content of a namespace * * @param string $namespace * @param array $data * @return void */ protected function write($namespace, array $data) { $file = $this->adapter->getFileName($namespace); $contents = $this->adapter->prepareForWriting($data); if (!$this->fileSystem->has($file)) { $this->fileSystem->write($file, $contents); } $this->fileSystem->update($file, $contents); }
/** * Erase a file. * * @param string $path * @throws IoWriteException */ public function erase($path) { try { $this->fs->update($path, ''); } catch (Error $ex) { throw new IoWriteException("File {$path} could not be erased.", $ex); } catch (Exception $ex) { throw new IoWriteException("File {$path} could not be erased.", $ex); } }
/** @inheritdoc */ public function renameConflicts(array $conflicts) { $replacements = []; $this->traverser->addVisitor($this->reNamer); foreach ($conflicts as $package => $types) { foreach ($types as $type => $versions) { foreach ($versions as $version => $files) { $composer = $this->reader->setPackage($package)->setVersion($version)->getComposerObject(); if ($this->hasNs($type)) { $split = $this->splitNsandClass($type); $fromNs = $split['ns']; $psrNs = $this->getPsrNs($composer, $fromNs); $toNs = $psrNs . $this->sanitizeVersionNo($version); $diff = str_replace($psrNs, '', $fromNs); if ($psrNs != $diff . '\\') { $toNs = $toNs . '\\' . $diff; } $newFullyQualifiedType = $toNs . '\\' . $split['class']; } else { $fromNs = $type; $toNs = $type . '_' . $this->sanitizeVersionNo($version); $newFullyQualifiedType = $toNs; } $this->reNamer->rename($fromNs, $toNs); $replacements[] = ['package' => $package, 'version' => $version, 'originalFullyQualifiedType' => $type, 'originalNamespace' => $fromNs, 'newFullyQualifiedType' => $newFullyQualifiedType, 'newNamespace' => $toNs, 'replacedIn' => $files]; foreach ($files as $file) { $fullPath = $this->vendorDir . '/' . $package . '/' . $version . '/' . $file; $src = $this->filesystem->read($fullPath); $ast = $this->parser->parse($src); $newAst = $this->traverser->traverse($ast); $code = $this->prettyPrinter->prettyPrintFile($newAst); $this->filesystem->update($fullPath, $code); } } } } $this->traverser->removeVisitor($this->reNamer); return $replacements; }
private function backupAndUpdate($path, $content) { if ($this->enableBackup) { $oldContent = $this->master->read($path); if ($oldContent !== false) { if ($this->backup->has($path)) { $this->backup->update($path, $oldContent); } else { $this->backup->write($path, $oldContent); } } } $this->master->update($path, $content); }
/** * Update an existing file. * * @param string $path The path of the existing file. * @param string $contents The file contents. * @param array $config An optional configuration array. * * @throws FileNotFoundException * * @return bool True on success, false on failure. */ public function update($path, $contents, array $config = []) { return $this->fileSystem->update($path, $contents, $config); }
/** * @param string $path * @param FilesystemInterface $remote * @param AdapterInterface $remoteAdapter */ private function mirrorFile($path, FilesystemInterface $remote, AdapterInterface $remoteAdapter) { $masterContent = $this->master->read($path); if (!is_string($masterContent)) { throw new \RuntimeException(sprintf('File %s could not be read on master storage', $path)); } $isOnRemote = $remote->has($path); if ($isOnRemote && !$remote->update($path, $masterContent)) { throw $this->createRuntimeException('File', $path, 'updated', $remoteAdapter); } elseif (!$isOnRemote && !$remote->write($path, $masterContent)) { throw $this->createRuntimeException('File', $path, 'created', $remoteAdapter); } }