Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Varien_Io_File ignored errors with error control operator #1269

Merged
merged 4 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/Varien/Image/Adapter/Gd2.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public function __construct()
*/
public function destruct()
{
@imagedestroy($this->_imageHandler);
if (is_resource($this->_imageHandler) || $this->_imageHandler instanceof \GdImage) {
@imagedestroy($this->_imageHandler);
}
}

/**
Expand Down
70 changes: 52 additions & 18 deletions lib/Varien/Io/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,13 @@ public function streamOpen($fileName, $mode = 'w+', $chmod = 0666)
ini_set('auto_detect_line_endings', 1);
}

@chdir($this->_cwd);
if ($this->_cwd) {
@chdir($this->_cwd);
}
$this->_streamHandler = @fopen($fileName, $mode);
@chdir($this->_iwd);
if ($this->_iwd) {
@chdir($this->_iwd);
}
if ($this->_streamHandler === false) {
throw new Exception('Error write to file ' . $this->getFilteredPath($fileName));
}
Expand Down Expand Up @@ -364,7 +368,9 @@ public function rmdir($dir, $recursive = false)
@chdir($this->_cwd);
}
$result = self::rmdirRecursive($dir, $recursive);
@chdir($this->_iwd);
if ($this->_iwd) {
@chdir($this->_iwd);
}
return $result;
}

Expand Down Expand Up @@ -509,7 +515,9 @@ protected function _IsValidSource($src)
protected function _isFilenameWriteable($filename)
{
$error = false;
@chdir($this->_cwd);
if ($this->_cwd) {
@chdir($this->_cwd);
}
if (file_exists($filename)) {
if (!is_writeable($filename)) {
$error = "File '{$this->getFilteredPath($filename)}' isn't writeable";
Expand All @@ -520,7 +528,9 @@ protected function _isFilenameWriteable($filename)
$error = "Folder '{$this->getFilteredPath($folder)}' isn't writeable";
}
}
@chdir($this->_iwd);
if ($this->_iwd) {
@chdir($this->_iwd);
}

if ($error) {
throw new Varien_Io_Exception($error);
Expand Down Expand Up @@ -554,29 +564,41 @@ protected function _checkSrcIsFile($src)
*/
public function filePutContent($filename, $src)
{
@chdir($this->_cwd);
if ($this->_cwd) {
@chdir($this->_cwd);
}
$result = @file_put_contents($filename, $src);
chdir($this->_iwd);
if ($this->_iwd) {
chdir($this->_iwd);
}
fballiano marked this conversation as resolved.
Show resolved Hide resolved

return $result;
}

public function fileExists($file, $onlyFile = true)
{
@chdir($this->_cwd);
if ($this->_cwd) {
@chdir($this->_cwd);
}
$result = file_exists($file);
if ($result && $onlyFile) {
$result = is_file($file);
}
@chdir($this->_iwd);
if ($this->_iwd) {
@chdir($this->_iwd);
}
return $result;
}

public function isWriteable($path)
{
@chdir($this->_cwd);
if ($this->_cwd) {
@chdir($this->_cwd);
}
$result = is_writeable($path);
@chdir($this->_iwd);
if ($this->_iwd) {
@chdir($this->_iwd);
}
return $result;
}

Expand Down Expand Up @@ -633,9 +655,13 @@ public function checkAndCreateFolder($folder, $mode = 0777)
*/
public function rm($filename)
{
@chdir($this->_cwd);
if ($this->_cwd) {
@chdir($this->_cwd);
}
$result = @unlink($filename);
@chdir($this->_iwd);
if ($this->_iwd) {
@chdir($this->_iwd);
}
return $result;
}

Expand All @@ -648,9 +674,13 @@ public function rm($filename)
*/
public function mv($src, $dest)
{
chdir($this->_cwd);
if ($this->_cwd) {
chdir($this->_cwd);
}
$result = @rename($src, $dest);
chdir($this->_iwd);
if ($this->_iwd) {
chdir($this->_iwd);
}
return $result;
}

Expand All @@ -663,9 +693,13 @@ public function mv($src, $dest)
*/
public function cp($src, $dest)
{
@chdir($this->_cwd);
if ($this->_cwd) {
@chdir($this->_cwd);
}
$result = @copy($src, $dest);
@chdir($this->_iwd);
if ($this->_iwd) {
@chdir($this->_iwd);
}
return $result;
}

Expand All @@ -681,7 +715,7 @@ public function chmod($filename, $mode)
if ($this->_cwd) {
chdir($this->_cwd);
}
$result = @chmod($filename, $mode);
$result = file_exists($filename) ? @chmod($filename, $mode) : false;
fballiano marked this conversation as resolved.
Show resolved Hide resolved
if ($this->_iwd) {
chdir($this->_iwd);
}
Expand Down