mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-02-08 00:52:01 +01:00
Fix: delete of files with [ and glob.
Conflicts: test/phpunit/FilesLibTest.php
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user