Browse Source

fix: Résoud #4417 : on ne peut pas vider un fichier d'archive. Le plugin râle et émet une nouvelle erreur en cas de tentative. Il est pratiquement impossible de trouver un tar vide dans la nature.

pull/4422/head
JamesRezo 5 months ago
parent
commit
206c680010
  1. 1
      lang/archiviste_fr.php
  2. 4
      paquet.xml
  3. 2
      phpunit.xml.dist
  4. 1
      src/AbstractArchiver.php
  5. 7
      src/SpipArchiver.php
  6. 4
      src/TarArchive.php
  7. 5
      tests/AbstractArchiverTest.php
  8. 66
      tests/SpipArchiverTest.php
  9. 8
      tests/bootstrap.php
  10. BIN
      var/tmp/tar/empty.tar

1
lang/archiviste_fr.php

@ -8,4 +8,5 @@ $GLOBALS[$GLOBALS['idx_lang']] = [
'fichier_lecture_seule' => 'Fichier en lecture seule',
'destination_inaccessible' => 'Desination inaccessible',
'fichier_deja_existant' => 'Le fichier existe déjà',
'tentative_de_vidage_du_fichier' => 'Impossible de vider compl&eagrace;tement vider un fichier d\'archive',
];

4
paquet.xml

@ -1,8 +1,8 @@
<paquet
prefix="archiviste"
categorie="outil"
version="2.1.0-dev"
etat="dev"
version="2.1.0-beta"
etat="test"
compatibilite="[4.1.0-dev;4.2.*]"
logo="prive/themes/spip/images/archiviste.svg"
documentation=""

2
phpunit.xml.dist

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
bootstrap="tests/bootstrap.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="true"

1
src/AbstractArchiver.php

@ -36,6 +36,7 @@ abstract class AbstractArchiver implements ArchiverInterface
5 => 'destination_inaccessible',
6 => 'fichier_deja_existant',
7 => 'fichier_inaccessible_en_lecture',
8 => 'tentative_de_vidage_du_fichier',
];
/**

7
src/SpipArchiver.php

@ -117,6 +117,13 @@ class SpipArchiver extends AbstractArchiver implements ArchiverInterface
$archive = $this->getArchive();
if ($archive) {
if (1 === $archive->open($this->fichier_archive, 'retrait')) {
// Vérifier qu'on ne cherche pas à vider l'archive
$reste = count($this->informer());
if ($reste === count($fichiers)) {
$this->setErreur(8);
return false;
}
$retour = $archive->remove($fichiers);
$archive->close();
}

4
src/TarArchive.php

@ -26,10 +26,6 @@ class TarArchive implements ArchiveInterface
2
);
if ('' === $this->tar->getFilename()) {
return 0;
}
return 1;
}

5
tests/AbstractArchiverTest.php

@ -5,11 +5,6 @@ namespace Spip\Archiver\Tests;
use PHPUnit\Framework\TestCase;
use Spip\Archiver\AbstractArchiver;
// si on lance les tests depuis tests/
if (function_exists('include_spip')) {
include_spip('inc/archives');
}
/**
* @covers \Spip\Archiver\AbstractArchiver
*

66
tests/SpipArchiverTest.php

@ -5,11 +5,6 @@ namespace Spip\Archiver\Tests;
use PHPUnit\Framework\TestCase;
use Spip\Archiver\SpipArchiver;
// si on lance les tests depuis tests/
if (function_exists('include_spip')) {
include_spip('inc/archives');
}
/**
* @covers \Spip\Archiver\AbstractArchiver
* @covers \Spip\Archiver\SpipArchiver
@ -28,24 +23,25 @@ class SpipArchiverTest extends TestCase
@file_put_contents(__DIR__ . '/../var/tmp/directory/test.txt', 'contenu de test');
$test_retirer_zip = new \ZipArchive();
$test_retirer_zip->open(__DIR__ . '/../var/tmp/retirer.zip', \ZipArchive::CREATE);
$test_retirer_zip->addFromString('test.txt', 'contenu de test');
$test_retirer_zip->close();
@mkdir(__DIR__ . '/../var/tmp/tar/directory');
$test_retirer_zip = new \ZipArchive();
$test_retirer_zip->open(__DIR__ . '/../var/tmp/retirer.zip', \ZipArchive::CREATE);
$test_retirer_zip->addFromString('test.txt', 'contenu de test');
$test_retirer_zip->addFromString('sub_directory/test2.txt', 'contenu de test2');
$test_retirer_zip->close();
@mkdir(__DIR__ . '/../var/tmp/tar/directory');
@file_put_contents(__DIR__ . '/../var/tmp/tar/directory/test.txt', 'contenu de test');
@mkdir(__DIR__ . '/../var/tmp/tar/directory/sub_directory');
@mkdir(__DIR__ . '/../var/tmp/tar/directory/sub_directory');
@file_put_contents(__DIR__ . '/../var/tmp/tar/directory/sub_directory/test2.txt', 'contenu de test2');
$test_retirer_tar = new \Spip\Archiver\TarArchive();
$test_retirer_tar->open(__DIR__ . '/../var/tmp/tar/retirer.tar', 'creation');
$test_retirer_tar->compress(__DIR__ . '/../var/tmp/tar/directory', [
__DIR__ . '/../var/tmp/tar/directory/test.txt',
__DIR__ . '/../var/tmp/tar/directory/sub_directory/test2.txt',
]);
@unlink(__DIR__ . '/../var/tmp/tar/directory/test.txt');
$test_retirer_tar = new \Spip\Archiver\TarArchive();
$test_retirer_tar->open(__DIR__ . '/../var/tmp/tar/retirer.tar', 'creation');
$test_retirer_tar->compress(__DIR__ . '/../var/tmp/tar/directory', [
__DIR__ . '/../var/tmp/tar/directory/test.txt',
__DIR__ . '/../var/tmp/tar/directory/sub_directory/test2.txt',
]);
@unlink(__DIR__ . '/../var/tmp/tar/directory/test.txt');
@unlink(__DIR__ . '/../var/tmp/tar/directory/sub_directory/test2.txt');
@rmdir(__DIR__ . '/../var/tmp/tar/directory/sub_directory');
@rmdir(__DIR__ . '/../var/tmp/tar/directory');
@rmdir(__DIR__ . '/../var/tmp/tar/directory/sub_directory');
@rmdir(__DIR__ . '/../var/tmp/tar/directory');
}
public static function tearDownAfterClass(): void
@ -126,15 +122,6 @@ class SpipArchiverTest extends TestCase
__DIR__ . '/../var/tmp/tar/test.tar',
'',
],
'empty-tar' => [
0,
[
'proprietes' => [],
'fichiers' => [],
],
__DIR__ . '/../var/tmp/tar/empty.tar',
'tar',
],
'tgz' => [
0,
[
@ -181,7 +168,7 @@ class SpipArchiverTest extends TestCase
[],
__DIR__ . '/../var/tmp/test.txt',
],
'destination-not-exists' => [
'destination-not-exists' => [
false,
5,
__DIR__ . '/../var/tmp/test.zip',
@ -261,11 +248,11 @@ class SpipArchiverTest extends TestCase
null,
],
'tar' => [
true,
0,
__DIR__ . '/../var/tmp/tar/emballer.tar',
'',
[__DIR__ . '/../var/tmp/directory/test.txt'],
true,
0,
__DIR__ . '/../var/tmp/tar/emballer.tar',
'',
[__DIR__ . '/../var/tmp/directory/test.txt'],
__DIR__ . '/../var/tmp/directory',
],
];
@ -288,7 +275,7 @@ class SpipArchiverTest extends TestCase
$this->assertTrue(file_exists($file), 'compressed file exists');
}
public function dataRetirer()
public function dataRetirer()
{
return [
'not-exists' => [
@ -305,6 +292,13 @@ class SpipArchiverTest extends TestCase
'',
['test.txt'],
],
'vider' => [
false,
8,
__DIR__ . '/../var/tmp/retirer.zip',
'',
['test.txt', 'sub_directory/test2.txt'],
],
'tar' => [
true,
0,

8
tests/bootstrap.php

@ -0,0 +1,8 @@
<?php
require_once __DIR__ . '/../vendor/autoload.php';
// si on lance les tests depuis tests/ dans une installation SPIP ...
if (function_exists('include_spip')) {
include_spip('inc/archives');
}

BIN
var/tmp/tar/empty.tar

Binary file not shown.
Loading…
Cancel
Save