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

Bug: Helper function directory_mirror() throws an error if destination directory exists (with overwrite option true) #5478

Closed
dmillard70 opened this issue Dec 17, 2021 · 2 comments · Fixed by #5493
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@dmillard70
Copy link

PHP Version

8.0

CodeIgniter4 Version

4.1.5

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

macOS

Which server did you use?

apache

Database

MySql 5.6

What happened?

Helper function directory_mirror() throws an error if destination directory exists (with overwrite option true), because there is no check whether directory already exists (filesystem_helper.php line 94).
I think this should be changed because the name of the function (* mirror *) suggests a function including subdirectories.

Steps to Reproduce

Just call twice directory_mirror() with same source (including subdirectories) and target path with overwrite option true.

Expected Output

Create sub directory only if subdirectory in target does not exist.
Consequently the name (* mirror *) perhaps suggests that you could mirror an path with all elements (including deleting no longer existing elements in destination)

Anything else?

No response

@dmillard70 dmillard70 added the bug Verified issues on the current code behavior or pull requests that will fix them label Dec 17, 2021
@kenjis
Copy link
Member

kenjis commented Dec 21, 2021

I confirmed the bug.

<?php

namespace App\Controllers;

class Home extends BaseController
{
    public function index()
    {
        helper('filesystem');
        directory_mirror(APPPATH . 'Config', WRITEPATH . 'tmp/Config');
    }
}
$ php public/index.php
$ php public/index.php 


[ErrorException]

mkdir(): File exists

at SYSTEMPATH/Helpers/filesystem_helper.php:94

Backtrace:
  1    [internal function]
       CodeIgniter\Debug\Exceptions()->errorHandler(2, 'mkdir(): File exists', '/Users/kenji/work/codeigniter/CodeIgniter4/system/Helpers/filesystem_helper.php', 94)

  2    SYSTEMPATH/Helpers/filesystem_helper.php:94
       mkdir('/Users/kenji/work/codeigniter/CodeIgniter4/writable/tmp/Config/Boot', 493)

  3    APPPATH/Controllers/Home.php:10
       directory_mirror('/Users/kenji/work/codeigniter/CodeIgniter4/app/Config', '/Users/kenji/work/codeigniter/CodeIgniter4/writable/tmp/Config')

  4    SYSTEMPATH/CodeIgniter.php:823
       App\Controllers\Home()->index()

  5    SYSTEMPATH/CodeIgniter.php:410
       CodeIgniter\CodeIgniter()->runController(Object(App\Controllers\Home))

  6    SYSTEMPATH/CodeIgniter.php:318
       CodeIgniter\CodeIgniter()->handleRequest(null, Object(Config\Cache), false)

  7    FCPATH/index.php:37
       CodeIgniter\CodeIgniter()->run()

@kenjis
Copy link
Member

kenjis commented Dec 22, 2021

@dmillard70 I sent a PR to fix: #5493

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants