banago / PHPloy

PHPloy - Incremental Git (S)FTP deployment tool that supports multiple servers, submodules and rollbacks.
http://wplancer.com/phploy/
1.42k stars 197 forks source link

Using base, mismatch between directories and files #367

Closed MircoBabin closed 2 years ago

MircoBabin commented 5 years ago

When using base = 'www/' and the server does not contain any directories, wrong directories will be created.

On the server the directory path/www/... wil be created. But the files are put in path/.../ without the base directory.

Looking into phploy.php I noticed that directory creation does not take base into account. First remote directories are created (with base in the filename). Then base is stripped and the file is transfered.

                // Make sure the folder exists in the FTP server.
                $dir = explode('/', dirname($file));
                $path = '';
                $ret = true;

                // Skip mkdir if dir is basedir
                if ($dir[0] !== '.') {
                    // Loop through each folder in the path /a/b/c/d.txt to ensure that it exists
                    // @TODO Can be improved by using: $filesystem->write('path/to/file.txt', 'contents');
                    for ($i = 0, $count = count($dir); $i < $count; ++$i) {
                        $path .= $dir[$i].'/';
                        if (!isset($pathsThatExist[$path])) {
                            if (!$this->connection->has($path)) {
                                $this->connection->createDir($path);
                                $this->cli->out(" + Created directory '$path'.");
                                $pathsThatExist[$path] = true;
                            } else {
                                $pathsThatExist[$path] = true;
                            }
                        }
                    }
                }

                $filePath = $this->repo.'/'.($this->currentSubmoduleName ? str_replace($this->currentSubmoduleName.'/', '', $file) : $file);
                $data = @file_get_contents($filePath);

                // It can happen the path is wrong, especially with included files.
                if ($data === false) {
                    $this->cli->error(' ! File not found - please check path: '.$filePath);
                    continue;
                }

                // If base is set, remove it from filename
                $remoteFile = $this->base ? preg_replace('/^'.preg_quote($this->base, '/').'/', '', $file) : $file;
MircoBabin commented 5 years ago

After replacing base='www/' with include[]='www/*' directory creation goes well.

But this has the disadvantage that root items (files in the root directory before the www directory) are also transfered. I had to exlude these manually one by one. (Only the www directory is transfered, other directories not, so that's good !).

[*]
    include[] = 'www/*'
    exclude[] = '*.htaccess.development'
    exclude[] = 'index.development.html'
    exclude[] = '.env.example'
    exclude[] = 'deploy.bat'
    exclude[] = 'phploy.ini'
    exclude[] = 'phploy.phar'

In my case the directory structure is:

/repo-root/index.development.html
/repo-root/.env.example
/repo-root/deploy.bat
/repo-root/phploy.ini
/repo-root/phploy.phar
/repo-root/customlogs/...
/repo-root/www/...
MircoBabin commented 5 years ago

Using include[]='www/' is very slow. Using include[]='www/*' will produce an error. But the error is ignorable.

 ^ 58 of 59 www/.../page.php
 ! File not found - please check path: /repo-root/www/*