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

OssnFile.php does not move directories across different volumes #1985

Closed
AntzCode opened this issue Aug 6, 2021 · 1 comment
Closed

OssnFile.php does not move directories across different volumes #1985

AntzCode opened this issue Aug 6, 2021 · 1 comment

Comments

@AntzCode
Copy link
Contributor

AntzCode commented Aug 6, 2021

This bug affects the file /classes/OssnFile.php at the method moveFiles().

An error occurs when using the copy() or rename() functions to move a directory from one volume to a different volume.

Eg:

PHP Warning: rename(): The first argument to copy() function cannot be a directory

This is a known bug in PHP:

https://bugs.php.net/bug.php?id=54097
https://bugs.launchpad.net/ubuntu/+source/php5/+bug/723330m

The method works as expected when moving files across volumes or when moving directories within the same volume. It is only whenever the $from and $to arguments are directories that are mounted on different volumes, then the error occurs.

For example, this will affect installations where /ossn_data is mounted on a different volume to that which the website files are mounted. When $Ossn->userdata and ossn_route()->www are mounted on separate volumes, it is impossible to upload and install components or themes.

While investigating the issue on the forked project, I happened to find a simple solution: by recursively calling the OssnFile::moveFiles() method for any filenames within the directory that are also directories and using the PHP rename function only if the filename points to a file that is not a directory, then the bug is never encountered:

public static function moveFiles($from, $to) {
    // etc.
    $files = scandir($from);
    foreach($files as $fname) {
        if($fname != '.' && $fname != '..') {
            if(is_dir($from . $fname)){
                self::moveFiles($from . $fname . DIRECTORY_SEPARATOR, $to . $fname . DIRECTORY_SEPARATOR);
            }else if(is_file($from . $fname)){
                rename($from . $fname, $to . $fname);
            }
        }
    }
    // etc.
}

This is the patch file of that change:

aa801418980bc0ce28529f292c4f3031f1ba5ee4.patch.txt

@lianglee
Copy link
Member

Merged already #1987

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants