Skip to content

Commit

Permalink
Resolve connection root for path prefixing
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdejonge committed Jan 29, 2022
1 parent 8239977 commit 813bc06
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
6 changes: 3 additions & 3 deletions FtpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public function __construct(
$this->connectionProvider = $connectionProvider ?: new FtpConnectionProvider();
$this->connectivityChecker = $connectivityChecker ?: new NoopCommandConnectivityChecker();
$this->visibilityConverter = $visibilityConverter ?: new PortableVisibilityConverter();
$this->prefixer = new PathPrefixer($connectionOptions->root());
$this->rootDirectory = $this->resolveConnectionRoot($this->connection());
$this->prefixer = new PathPrefixer($this->rootDirectory);
$this->mimeTypeDetector = $mimeTypeDetector ?: new FinfoMimeTypeDetector();
}

Expand All @@ -119,7 +120,6 @@ private function connection()
start:
if ( ! $this->hasFtpConnection()) {
$this->connection = $this->connectionProvider->createConnection($this->connectionOptions);
$this->rootDirectory = $this->resolveConnectionRoot($this->connection);

return $this->connection;
}
Expand Down Expand Up @@ -596,7 +596,7 @@ private function ensureDirectoryExists(string $dirname, ?string $visibility): vo
$connection = $this->connection();

$dirPath = '';
$parts = explode('/', rtrim($dirname, '/'));
$parts = explode('/', trim($dirname, '/'));
$mode = $visibility ? $this->visibilityConverter->forDirectory($visibility) : false;

foreach ($parts as $part) {
Expand Down
10 changes: 4 additions & 6 deletions FtpAdapterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,11 @@ public function using_empty_string_for_root(): void
$this->runScenario(function () use ($options) {
$adapter = new FtpAdapter($options);

$adapter->write('dirname/path.txt', 'contents', new Config([
Config::OPTION_VISIBILITY => Visibility::PUBLIC,
Config::OPTION_DIRECTORY_VISIBILITY => Visibility::PUBLIC
]));
$adapter->write('dirname1/dirname2/path.txt', 'contents', new Config());
$adapter->write('dirname1/dirname2/path.txt', 'contents', new Config());

$this->assertTrue($adapter->fileExists('dirname/path.txt'));
$this->assertSame('contents', $adapter->read('dirname/path.txt'));
$this->assertTrue($adapter->fileExists('dirname1/dirname2/path.txt'));
$this->assertSame('contents', $adapter->read('dirname1/dirname2/path.txt'));
});
}

Expand Down

0 comments on commit 813bc06

Please sign in to comment.