Skip to content
Snippets Groups Projects
Commit c84427bd authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Fix: delete of files with [ and glob.

Conflicts:
	test/phpunit/FilesLibTest.php
parent f8b133da
No related branches found
No related tags found
No related merge requests found
......@@ -751,12 +751,14 @@ function dol_delete_file($file,$disableglob=0,$nophperrors=0,$nohook=0,$object=n
{
$error=0;
//print "x".$file." ".$disableglob;
//print "x".$file." ".$disableglob;exit;
$ok=true;
$file_osencoded=dol_osencode($file); // New filename encoded in OS filesystem encoding charset
if (empty($disableglob) && ! empty($file_osencoded))
{
foreach (glob($file_osencoded) as $filename)
$globencoded=str_replace('[','\[',$file_osencoded);
$globencoded=str_replace(']','\]',$globencoded);
foreach (glob($globencoded) as $filename)
{
if ($nophperrors) $ok=@unlink($filename); // The unlink encapsulated by dolibarr
else $ok=unlink($filename); // The unlink encapsulated by dolibarr
......
......@@ -326,7 +326,7 @@ class FilesLibTest extends PHPUnit_Framework_TestCase
// Again to test with overwriting=1
$result=dol_copy($file, $conf->admin->dir_temp.'/file.csv',0,1);
print __METHOD__." result=".$result."\n";
$this->assertGreaterThanOrEqual(1,$result); // Should be 1
$this->assertGreaterThanOrEqual(1,$result,'copy destination already exists, overwrite'); // Should be 1
// Again to test with overwriting=1
$result=dol_move($conf->admin->dir_temp.'/file.csv',$conf->admin->dir_temp.'/file2.csv',0,1);
......@@ -340,7 +340,17 @@ class FilesLibTest extends PHPUnit_Framework_TestCase
// Again to test no erreor when deleteing a non existing file
$result=dol_delete_file($conf->admin->dir_temp.'/file2.csv');
print __METHOD__." result=".$result."\n";
$this->assertTrue($result);
$this->assertTrue($result,'delete file that does not exists');
// Test copy with special char / delete with blob
$result=dol_copy($file, $conf->admin->dir_temp.'/file with [x] and é.csv',0,1);
print __METHOD__." result=".$result."\n";
$this->assertGreaterThanOrEqual(1,$result,'copy file with special char, overwrite'); // Should be 1
// Try to delete using a glob criteria
$result=dol_delete_file($conf->admin->dir_temp.'/file with [x]*é.csv');
print __METHOD__." result=".$result."\n";
$this->assertTrue($result,'delete file using glob criteria');
}
/**
......@@ -377,4 +387,4 @@ class FilesLibTest extends PHPUnit_Framework_TestCase
$this->assertEquals(0,count($result));
}
}
?>
\ No newline at end of file
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment