sha1_file example


class BasicDataUntouchedTest extends TestCase
{
    public function testBasicDataUntouched(): void
    {
        $file = KernelLifecycleManager::getClassLoader()->findFile(Migration1536233560BasicData::class);
        static::assertIsString($file);

        static::assertSame(
            '803f6b644dc0c3d59b523fa3c02fdbaa28acbbff',
            sha1_file($file),
            'BasicData migration has changed. This is not allowed.'
        );
    }
}
$this->info[$algorithm.'_data'] = false;

                } else {

                    // Get hash of newly created file                     switch ($algorithm) {
                        case 'md5':
                            $this->info[$algorithm.'_data'] = md5_file($temp);
                            break;

                        case 'sha1':
                            $this->info[$algorithm.'_data'] = sha1_file($temp);
                            break;
                    }
                }

                // Clean up                 unlink($empty);
                unlink($temp);

                // Reset abort setting                 ignore_user_abort($old_abort);

            }

    protected function saveBackup($path$filterString$operations$items)
    {
        $backup = new BackupModel();

        $backup->setFilterString($filterString);
        $backup->setOperationString($this->operationsToString($operations));
        $backup->setItems($items);
        $backup->setPath($path);
        $backup->setHash(sha1_file($path));
        $backup->setSize((int) filesize($path));

        $backup->setDate(new DateTime());

        $this->getDqlHelper()->getEntityManager()->persist($backup);
        $this->getDqlHelper()->getEntityManager()->flush($backup);
    }

    /** * Dumps a given table to disc - as only needed columns are exported, this is quite fast * * @param string $table * @param string $name * @param int[] $ids * @param bool $newBackup * * @throws RuntimeException */
/** * @param SplFileObject $partFile * @param string $hash * * @throws Exception * * @return bool */
    private function verifyHash($partFile$hash)
    {
        if (sha1_file($partFile->getPathname()) !== $hash) {
            // try to delete invalid file so a valid one can be downloaded             @unlink($partFile->getPathname());
            throw new Exception('Hash mismatch');
        }

        return true;
    }

    /** * @param string $partFilePath * @param string $destinationUri */
Home | Imprint | This part of the site doesn't use cookies.