Skip to content

Commit add1065

Browse files
authored
Fix Varien_Io_File ignored errors with error control operator (#1269)
1 parent e890d7c commit add1065

File tree

2 files changed

+55
-19
lines changed

2 files changed

+55
-19
lines changed

lib/Varien/Image/Adapter/Gd2.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ public function __construct()
5454
*/
5555
public function destruct()
5656
{
57-
@imagedestroy($this->_imageHandler);
57+
if (is_resource($this->_imageHandler) || $this->_imageHandler instanceof \GdImage) {
58+
@imagedestroy($this->_imageHandler);
59+
}
5860
}
5961

6062
/**

lib/Varien/Io/File.php

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,13 @@ public function streamOpen($fileName, $mode = 'w+', $chmod = 0666)
134134
ini_set('auto_detect_line_endings', 1);
135135
}
136136

137-
@chdir($this->_cwd);
137+
if ($this->_cwd) {
138+
@chdir($this->_cwd);
139+
}
138140
$this->_streamHandler = @fopen($fileName, $mode);
139-
@chdir($this->_iwd);
141+
if ($this->_iwd) {
142+
@chdir($this->_iwd);
143+
}
140144
if ($this->_streamHandler === false) {
141145
throw new Exception('Error write to file ' . $this->getFilteredPath($fileName));
142146
}
@@ -365,7 +369,9 @@ public function rmdir($dir, $recursive = false)
365369
@chdir($this->_cwd);
366370
}
367371
$result = self::rmdirRecursive($dir, $recursive);
368-
@chdir($this->_iwd);
372+
if ($this->_iwd) {
373+
@chdir($this->_iwd);
374+
}
369375
return $result;
370376
}
371377

@@ -510,7 +516,9 @@ protected function _IsValidSource($src)
510516
protected function _isFilenameWriteable($filename)
511517
{
512518
$error = false;
513-
@chdir($this->_cwd);
519+
if ($this->_cwd) {
520+
@chdir($this->_cwd);
521+
}
514522
if (file_exists($filename)) {
515523
if (!is_writeable($filename)) {
516524
$error = "File '{$this->getFilteredPath($filename)}' isn't writeable";
@@ -521,7 +529,9 @@ protected function _isFilenameWriteable($filename)
521529
$error = "Folder '{$this->getFilteredPath($folder)}' isn't writeable";
522530
}
523531
}
524-
@chdir($this->_iwd);
532+
if ($this->_iwd) {
533+
@chdir($this->_iwd);
534+
}
525535

526536
if ($error) {
527537
throw new Varien_Io_Exception($error);
@@ -555,29 +565,41 @@ protected function _checkSrcIsFile($src)
555565
*/
556566
public function filePutContent($filename, $src)
557567
{
558-
@chdir($this->_cwd);
568+
if ($this->_cwd) {
569+
@chdir($this->_cwd);
570+
}
559571
$result = @file_put_contents($filename, $src);
560-
chdir($this->_iwd);
572+
if ($this->_iwd) {
573+
chdir($this->_iwd);
574+
}
561575

562576
return $result;
563577
}
564578

565579
public function fileExists($file, $onlyFile = true)
566580
{
567-
@chdir($this->_cwd);
581+
if ($this->_cwd) {
582+
@chdir($this->_cwd);
583+
}
568584
$result = file_exists($file);
569585
if ($result && $onlyFile) {
570586
$result = is_file($file);
571587
}
572-
@chdir($this->_iwd);
588+
if ($this->_iwd) {
589+
@chdir($this->_iwd);
590+
}
573591
return $result;
574592
}
575593

576594
public function isWriteable($path)
577595
{
578-
@chdir($this->_cwd);
596+
if ($this->_cwd) {
597+
@chdir($this->_cwd);
598+
}
579599
$result = is_writeable($path);
580-
@chdir($this->_iwd);
600+
if ($this->_iwd) {
601+
@chdir($this->_iwd);
602+
}
581603
return $result;
582604
}
583605

@@ -634,9 +656,13 @@ public function checkAndCreateFolder($folder, $mode = 0777)
634656
*/
635657
public function rm($filename)
636658
{
637-
@chdir($this->_cwd);
659+
if ($this->_cwd) {
660+
@chdir($this->_cwd);
661+
}
638662
$result = @unlink($filename);
639-
@chdir($this->_iwd);
663+
if ($this->_iwd) {
664+
@chdir($this->_iwd);
665+
}
640666
return $result;
641667
}
642668

@@ -649,9 +675,13 @@ public function rm($filename)
649675
*/
650676
public function mv($src, $dest)
651677
{
652-
chdir($this->_cwd);
678+
if ($this->_cwd) {
679+
chdir($this->_cwd);
680+
}
653681
$result = @rename($src, $dest);
654-
chdir($this->_iwd);
682+
if ($this->_iwd) {
683+
chdir($this->_iwd);
684+
}
655685
return $result;
656686
}
657687

@@ -664,9 +694,13 @@ public function mv($src, $dest)
664694
*/
665695
public function cp($src, $dest)
666696
{
667-
@chdir($this->_cwd);
697+
if ($this->_cwd) {
698+
@chdir($this->_cwd);
699+
}
668700
$result = @copy($src, $dest);
669-
@chdir($this->_iwd);
701+
if ($this->_iwd) {
702+
@chdir($this->_iwd);
703+
}
670704
return $result;
671705
}
672706

@@ -682,7 +716,7 @@ public function chmod($filename, $mode)
682716
if ($this->_cwd) {
683717
chdir($this->_cwd);
684718
}
685-
$result = @chmod($filename, $mode);
719+
$result = file_exists($filename) ? @chmod($filename, $mode) : false;
686720
if ($this->_iwd) {
687721
chdir($this->_iwd);
688722
}

0 commit comments

Comments
 (0)