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

Cronjob errors No such file or directory (errno 2) in /lib/Varien/Io/File.php #1173

Closed
buderus199 opened this issue Apr 13, 2020 · 3 comments · Fixed by #1245
Closed

Cronjob errors No such file or directory (errno 2) in /lib/Varien/Io/File.php #1173

buderus199 opened this issue Apr 13, 2020 · 3 comments · Fixed by #1245
Assignees
Milestone

Comments

@buderus199
Copy link

buderus199 commented Apr 13, 2020

Preconditions

  1. Mailchimp for Magento 1.1.20
  2. Magento 1.9.4.3, PHP 7.2, MySQL 5.6

Steps to reproduce

  1. When cronjobs mailchimp_bulksync_ecommerce_data & mailchimp_bulksync_subscriber_data are triggered, I get this kind of errors:

PHP Warning: chdir(): No such file or directory (errno 2) in /lib/Varien/Io/File.php on line 444
PHP Warning: chdir(): No such file or directory (errno 2) in /lib/Varien/Io/File.php on line 446

  1. Using 1.1.18 everything worked ok. After some digging I found that starting 1.1.19 mailchimp extension file read code is relying on Magento "Varien_Io_File" class ($this->_ioFile->read($filename);) instead of file_get_contents function like in 1.1.18.
  2. Varien_Io_File read function is then triggering error because of chdir($this->_cwd); and chdir($this->_iwd); not set.
    Code:
    /**
     * Read a file to result, file or stream
     *
     * If $dest is null the output will be returned.
     * Otherwise it will be saved to the file or stream and operation result is returned.
     *
     * @param string $filename
     * @param string|resource $dest
     * @return boolean|string
     */
    public function read($filename, $dest=null)
    {
        if (!is_null($dest)) {
            chdir($this->_cwd);
            $result = @copy($filename, $dest);
            chdir($this->_iwd);
            return $result;
        }

        chdir($this->_cwd);
        $result = @file_get_contents($filename);
        chdir($this->_iwd);

        return $result;
    }
  1. Looking kinda Magento Varien_Io_File->read() problem, but are there any possibilities to solve this on Mailchimp extension side? One way to solve could be to to use @ in front of chdir but I suppose that is not optimal.

Expected result

  1. No cronjob return errors

Actual result

  1. Cronjob Email errors:

PHP Warning: chdir(): No such file or directory (errno 2) in /lib/Varien/Io/File.php on line 444
PHP Warning: chdir(): No such file or directory (errno 2) in /lib/Varien/Io/File.php on line 446

@Santiagoebizmarts
Copy link
Contributor

Hello @buderus199

Thanks for your feedback. Our initial tests do not replicate this problem.
Anyways we will look into the file managing process and see if we are able to find why this happens to you.

Kind Regards.

@aadmathijssen
Copy link
Contributor

Hi @buderus199 and @Santiagoebizmarts, I also ran into this issue today when checking the system.log of a Magento 1 application.

It looks like the Ebizmarts_MailChimp_Helper_File::read method does not use Varien_Io_File::read correctly: its intended use seems to be to first call Varien_Io_File::open to make sure the $_cwd and $_iwd instance variables are set.

Examples of this can be found in the Magento core:

  • Mage_Api_Model_Server_Adapter_Soap::run: in this method the Varien_Io_File::read method is called on a relative path, so the Varien_Io_File::open has to be called to prepare the initial and current working directory locations.
  • Mage_Core_Model_Translate::getTemplateFile: in this method the Varien_Io_File::read method is called on an absolute path, but the Varien_Io_File::open is called nonetheless (probably to avoid the PHP warnings).

As the Ebizmarts_MailChimp_Helper_File::read is only called on absolute paths, a similar solution to that of Mage_Core_Model_Translate::getTemplateFile might seem to be right solution, however this might have side-effects, because this will actually change the current working directory and will set the $_cwd and $_iwd instance variables that are used in other Varien_Io_File methods.

Therefore I would propose something simpler by copying the essential part of Varien_Io_File::read into Ebizmarts_MailChimp_Helper_File::read. This is just a one-line change:

    public function read($filename){
        return @file_get_contents($filename);
    }

@TheFrakes
Copy link

@aadmathijssen I have encountered the same issue and I want to try your fix. Can you please add which file in which directory you edited?

gonzaloebiz added a commit that referenced this issue Jul 27, 2021
@gonzaloebiz gonzaloebiz linked a pull request Jul 27, 2021 that will close this issue
@gonzaloebiz gonzaloebiz self-assigned this Jul 27, 2021
@gonzaloebiz gonzaloebiz added this to the 1.1.22 milestone Jul 27, 2021
gonzaloebiz added a commit that referenced this issue Jul 27, 2021
gonzaloebiz added a commit that referenced this issue Jul 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants