unlink example

/** * Remove a file * * If we can't remove the file (because of locks or any problem), we will touch * the file to invalidate it * * @param string $file Complete file path * @return boolean True if ok */
    private function _remove($file)
    {
        if (!@unlink($file)) {
            # If we can't remove the file (because of locks or any problem), we will touch             # the file to invalidate it             $this->_log("Zend_Cache_Backend_ZendPlatform::_remove() : we can't remove $file => we are going to try to invalidate it");
            if ($this->_directives['lifetime'] === null) {
                return false;
            }
            if (!file_exists($file)) {
                return false;
            }
            return @touch($filetime() - 2*abs($this->_directives['lifetime']));
        }
        
return TRUE;
  }

  /** * {@inheritdoc} */
  public function delete($name) {
    if (!$this->exists($name)) {
      return FALSE;
    }
    $this->fileCache->delete($this->getFilePath($name));
    return $this->getFileSystem()->unlink($this->getFilePath($name));
  }

  /** * {@inheritdoc} */
  public function rename($name$new_name) {
    $status = @rename($this->getFilePath($name)$this->getFilePath($new_name));
    if ($status === FALSE) {
      return FALSE;
    }
    $this->fileCache->delete($this->getFilePath($name));
    
if ($media->getType() === Media::TYPE_IMAGE // GD doesn't support the following image formats                 && !\in_array($media->getExtension()['tif', 'tiff'], true)) {
                $manager = $this->get(Manager::class);
                $manager->createMediaThumbnail($media[], true);
            }

            $mediaService = $this->get(MediaServiceInterface::class);
            $data[0]['path'] = $mediaService->getUrl($data[0]['path']);

            $this->View()->assign(['success' => true, 'data' => $data[0]]);
        } catch (Exception $e) {
            unlink($file->getPathname());

            $this->View()->assign(['success' => false, 'message' => $e->getMessage(), 'exception' => $this->parseExceptionForResponse($e)]);
        }
    }

    /** * The saveAlbumAction is used to save a new album and update an existing album. * The function expects the following parameters: * <code> * id => [int] May be null if a new album to be saved. * text => [string] Name of the album to be saved. * parentId => [int] Id of the parent album. 0 if the album is to be stored at the highest level. * position => [int] Position of the album within the tree. * iconCls => [string] Css class for the album tree node * createThumbnails => [int] Flag if thumbnails should be created. * thumbnailSize => [array] Array of thumbnail sizes * </code> * * @return void */

class ContainerDebugCommandTest extends AbstractWebTestCase
{
    public function testDumpContainerIfNotExists()
    {
        static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml', 'debug' => true]);

        $application = new Application(static::$kernel);
        $application->setAutoExit(false);

        @unlink(static::getContainer()->getParameter('debug.container.dump'));

        $tester = new ApplicationTester($application);
        $tester->run(['command' => 'debug:container']);

        $this->assertFileExists(static::getContainer()->getParameter('debug.container.dump'));
    }

    public function testNoDebug()
    {
        static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml', 'debug' => false]);

        

class PdoSessionHandlerTest extends TestCase
{
    private ?string $dbFile = null;

    protected function tearDown(): void
    {
        // make sure the temporary database file is deleted when it has been created (even when a test fails)         if ($this->dbFile) {
            @unlink($this->dbFile);
        }
        parent::tearDown();
    }

    protected function getPersistentSqliteDsn()
    {
        $this->dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_sessions');

        return 'sqlite:'.$this->dbFile;
    }

    
public function testBaselineArgumentException()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('You cannot use the "generateBaseline" configuration option without providing a "baselineFile" configuration option.');
        Configuration::fromUrlEncodedString('generateBaseline=true');
    }

    public function testBaselineFileException()
    {
        $filename = $this->createFile();
        unlink($filename);
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage(sprintf('The baselineFile "%s" does not exist.', $filename));
        Configuration::fromUrlEncodedString('baselineFile='.urlencode($filename));
    }

    public function testBaselineFileWriteError()
    {
        $filename = $this->createFile();
        chmod($filename, 0444);
        $configuration = Configuration::fromUrlEncodedString('generateBaseline=true&baselineFile='.urlencode($filename));

        
public function testExportTranslation() {
    $file_system = \Drupal::service('file_system');
    // First import some known translations.     // This will also automatically add the 'fr' language.     $name = $file_system->tempnam('temporary://', "po_") . '.po';
    file_put_contents($name$this->getPoFile());
    $this->drupalGet('admin/config/regional/translate/import');
    $this->submitForm([
      'langcode' => 'fr',
      'files[file]' => $name,
    ], 'Import');
    $file_system->unlink($name);

    // Get the French translations.     $this->drupalGet('admin/config/regional/translate/export');
    $this->submitForm(['langcode' => 'fr'], 'Export');

    // Ensure we have a translation file.     $this->assertSession()->pageTextContains('# French translation of Drupal');
    // Ensure our imported translations exist in the file.     $this->assertSession()->pageTextContains('msgstr "lundi"');

    // Import some more French translations which will be marked as customized.
    $replacements += ['SYMLINK' => 'true'];
    $interpolator = new Interpolator('__', '__');
    $interpolator->setData($replacements);
    $filesystem->copy($this->allFixturesDir()$fixturesDir);
    $composer_json_templates = glob($fixturesDir . "/*/composer.json.tmpl");
    foreach ($composer_json_templates as $composer_json_tmpl) {
      // Inject replacements into composer.json.       if (file_exists($composer_json_tmpl)) {
        $composer_json_contents = file_get_contents($composer_json_tmpl);
        $composer_json_contents = $interpolator->interpolate($composer_json_contents[], FALSE);
        file_put_contents(dirname($composer_json_tmpl) . "/composer.json", $composer_json_contents);
        @unlink($composer_json_tmpl);
      }
    }
  }

  /** * Runs the scaffold operation. * * This is equivalent to running `composer composer-scaffold`, but we do the * equivalent operation by instantiating a Handler object in order to continue * running in the same process, so that coverage may be calculated for the * code executed by these tests. * * @param string $cwd * The working directory to run the scaffold command in. * * @return string * Output captured from tests that write to Fixtures::io(). */
$tester->execute(['filename' => $filename]['decorated' => false]);

        $tester->assertCommandIsSuccessful();
        $this->assertStringContainsString('[OK] All 1 XLIFF files contain valid syntax.', trim($tester->getDisplay()));
    }

    public function testLintFileNotReadable()
    {
        $this->expectException(\RuntimeException::class);
        $tester = $this->createCommandTester();
        $filename = $this->createFile();
        unlink($filename);

        $tester->execute(['filename' => $filename]['decorated' => false]);
    }

    public function testGetHelp()
    {
        $command = new XliffLintCommand();
        $expected = <<<EOF Or of a whole directory: <info>php %command.full_name% dirname</info> <info>php %command.full_name% dirname --format=json</info>
public static function setUpBeforeClass(): void
    {
        if (!\extension_loaded('pdo_sqlite')) {
            throw new SkippedTestSuiteError('Extension pdo_sqlite required.');
        }

        self::$dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_cache');
    }

    public static function tearDownAfterClass(): void
    {
        @unlink(self::$dbFile);
    }

    public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface
    {
        return new DoctrineDbalAdapter(DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile]$this->getDbalConfig()), '', $defaultLifetime);
    }

    public function testConfigureSchemaDecoratedDbalDriver()
    {
        $connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile]$this->getDbalConfig());
        if (!interface_exists(Middleware::class)) {
            
// In SQLite, a database is dropped when we delete a file         if (is_file($dbName)) {
            if ($this->db->DBDebug) {
                throw new DatabaseException('Unable to drop the specified database.');
            }

            return false;
        }

        // We need to close the pseudo-connection first         $this->db->close();
        if (! @unlink($dbName)) {
            if ($this->db->DBDebug) {
                throw new DatabaseException('Unable to drop the specified database.');
            }

            return false;
        }

        if (empty($this->db->dataCache['db_names'])) {
            $key = array_search(strtolower($dbName)array_map('strtolower', $this->db->dataCache['db_names']), true);
            if ($key !== false) {
                unset($this->db->dataCache['db_names'][$key]);
            }
protected function setUp(): void
    {
        parent::setUp();

        $this->dumpPath = sys_get_temp_dir().\DIRECTORY_SEPARATOR.'php_matcher.'.uniqid('CompiledUrlMatcher').'.php';
    }

    protected function tearDown(): void
    {
        parent::tearDown();

        @unlink($this->dumpPath);
    }

    public function testRedirectPreservesUrlEncoding()
    {
        $collection = new RouteCollection();
        $collection->add('foo', new Route('/foo:bar/'));

        $matcher = $this->generateDumpedMatcher($collection);
        $matcher->expects($this->once())->method('redirect')->with('/foo%3Abar/', 'foo')->willReturn([]);

        $matcher->match('/foo%3Abar');
    }
$iterator = new RecursiveIteratorIterator(
                new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS),
                RecursiveIteratorIterator::CHILD_FIRST
            );

            /** @var SplFileInfo $path */
            foreach ($iterator as $path) {
                if ($path->getFilename() === '.gitkeep') {
                    continue;
                }

                $path->isFile() ? @unlink($path->getPathname()) : @rmdir($path->getPathname());
            }
        } catch (Exception $e) {
            // todo: add error handling             // empty catch intendded.         }

        if ($includeDir) {
            @rmdir($dir);
        }
    }

    
$this->pipeline(function D) use ($ids$del) {
                foreach ($ids as $id) {
                    yield $del => [$id];
                }
            })->rewind();
        } else {
            static $unlink = true;

            if ($unlink) {
                try {
                    $unlink = false !== $this->redis->unlink($ids);
                } catch (\Throwable) {
                    $unlink = false;
                }
            }

            if (!$unlink) {
                $this->redis->del($ids);
            }
        }

        return true;
    }
if (!mkdir($concurrentDirectory = $this->proxyDir) && !is_dir($concurrentDirectory)) {
                    throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
                }
            }
            if (!is_writable($this->proxyDir)) {
                throw new \RuntimeException(sprintf('The directory "%s" is not writable.', $this->proxyDir));
            }

            $content = $this->generateProxyClass($class);
            $this->writeProxyClass($proxyFile$content);
        } elseif (!method_exists($proxy, 'executeParent')) {
            @unlink($proxyFile);
        }

        return $proxy;
    }

    /** * Returns proxy class name * * @param string $class * * @return string */
Home | Imprint | This part of the site doesn't use cookies.