diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5c08f719..2b9975e5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,6 +7,7 @@ env: FTP_USER: username FTP_PASSWORD: password FTP_PORT: 21 + FTP_ROOT: /home/vsftpd/username jobs: lunix-tests: @@ -41,7 +42,7 @@ jobs: extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, mysql, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, redis coverage: none - - run: docker run --net=host -p 21:21 -e USER=$FTP_USER -e PASS=$FTP_PASSWORD -d --name ftp papacdev/vsftpd + - run: docker run --net=host -p 21:21 -p 20:20 -p 12020:12020 -p 12021:12021 -p 12022:12022 -p 12023:12023 -p 12024:12024 -p 12025:12025 -e USER=$FTP_USER -e PASS=$FTP_PASSWORD -d --name ftp -v $(pwd)/:/ftp/$FTP_USER papacdev/vsftpd - run: docker run -p 1080:1080 -p 1025:1025 -d --name maildev soulteary/maildev - run: docker run -p 6379:6379 -d --name redis redis - run: docker run -p 5432:5432 --name postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=postgres -e POSTGRES_PASSWORD=postgres -d postgis/postgis diff --git a/src/Storage/Service/FTPService.php b/src/Storage/Service/FTPService.php index c0f79790..7fc5026b 100644 --- a/src/Storage/Service/FTPService.php +++ b/src/Storage/Service/FTPService.php @@ -177,6 +177,8 @@ public function changePath(?string $path = null) if ($base_path && (!@ftp_chdir($this->connection, $base_path))) { throw new RuntimeException('Root is invalid or does not exist: ' . $base_path); } + + ftp_pwd($this->connection); } /** @@ -483,13 +485,18 @@ public function isFile(string $filename): bool */ public function isDirectory(string $dirname): bool { - $listing = $this->listDirectoryContents(); + $original_directory = ftp_pwd($this->connection); - $dirname_info = array_filter($listing, function ($item) use ($dirname) { - return $item['type'] === 'directory' && $item['name'] === $dirname; - }); + // Test if you can change directory to $dirname + // suppress errors in case $dir is not a file or not a directory + if (!@ftp_chdir($this->connection, $dirname)) { + return false; + } - return count($dirname_info) !== 0; + // If it is a directory, then change the directory back to the original directory + ftp_chdir($this->connection, $original_directory); + + return true; } /** diff --git a/tests/Config/stubs/storage.php b/tests/Config/stubs/storage.php index 1cbeed83..4fcc382a 100644 --- a/tests/Config/stubs/storage.php +++ b/tests/Config/stubs/storage.php @@ -23,7 +23,7 @@ */ 'ftp' => [ "driver" => "ftp", - 'hostname' => app_env('FTP_HOST', '127.0.0.1'), + 'hostname' => app_env('FTP_HOST', 'localhost'), 'password' => app_env('FTP_PASSWORD', 'password'), 'username' => app_env('FTP_USERNAME', 'username'), 'port' => app_env('FTP_PORT', 21),