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

Fix prefix-related issues in WebDAV adapter #1533

Merged
merged 2 commits into from
Sep 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions src/WebDAV/WebDAVAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct(

public function fileExists(string $path): bool
{
$location = $this->prefixer->prefixPath($this->encodePath($path));
$location = $this->encodePath($this->prefixer->prefixPath($path));

try {
$properties = $this->client->propFind($location, ['{DAV:}resourcetype', '{DAV:}iscollection']);
Expand Down Expand Up @@ -90,7 +90,7 @@ protected function encodePath(string $path): string

public function directoryExists(string $path): bool
{
$location = $this->prefixer->prefixPath($this->encodePath($path));
$location = $this->encodePath($this->prefixer->prefixPath($path));

try {
$properties = $this->client->propFind($location, ['{DAV:}resourcetype', '{DAV:}iscollection']);
Expand Down Expand Up @@ -121,7 +121,7 @@ public function writeStream(string $path, $contents, Config $config): void
private function upload(string $path, mixed $contents): void
{
$this->createParentDirFor($path);
$location = $this->prefixer->prefixPath($this->encodePath($path));
$location = $this->encodePath($this->prefixer->prefixPath($path));

try {
$response = $this->client->request('PUT', $location, $contents);
Expand All @@ -137,7 +137,7 @@ private function upload(string $path, mixed $contents): void

public function read(string $path): string
{
$location = $this->prefixer->prefixPath($this->encodePath($path));
$location = $this->encodePath($this->prefixer->prefixPath($path));

try {
$response = $this->client->request('GET', $location);
Expand All @@ -154,7 +154,7 @@ public function read(string $path): string

public function readStream(string $path)
{
$location = $this->prefixer->prefixPath($this->encodePath($path));
$location = $this->encodePath($this->prefixer->prefixPath($path));

try {
$url = $this->client->getAbsoluteUrl($location);
Expand All @@ -174,7 +174,7 @@ public function readStream(string $path)

public function delete(string $path): void
{
$location = $this->prefixer->prefixPath($this->encodePath($path));
$location = $this->encodePath($this->prefixer->prefixPath($path));

try {
$response = $this->client->request('DELETE', $location);
Expand All @@ -192,7 +192,7 @@ public function delete(string $path): void

public function deleteDirectory(string $path): void
{
$location = $this->prefixer->prefixDirectoryPath($this->encodePath($path));
$location = $this->encodePath($this->prefixer->prefixDirectoryPath($path));

try {
$statusCode = $this->client->request('DELETE', $location)['statusCode'];
Expand All @@ -209,13 +209,17 @@ public function deleteDirectory(string $path): void

public function createDirectory(string $path, Config $config): void
{
$parts = explode('/', $path);
$parts = explode('/', $this->prefixer->prefixDirectoryPath($path));
$directoryParts = [];

foreach ($parts as $directory) {
if ($directory === '.' || $directory === '') {
return;
}

$directoryParts[] = $directory;
$directoryPath = implode('/', $directoryParts);
$location = $this->prefixer->prefixDirectoryPath($this->encodePath($directoryPath));
$location = $this->encodePath($directoryPath);

if ($this->directoryExists($directoryPath)) {
continue;
Expand Down Expand Up @@ -268,7 +272,7 @@ public function fileSize(string $path): FileAttributes

public function listContents(string $path, bool $deep): iterable
{
$location = $this->prefixer->prefixDirectoryPath($this->encodePath($path));
$location = $this->encodePath($this->prefixer->prefixDirectoryPath($path));
$response = $this->client->propFind($location, self::FIND_PROPERTIES, 1);
array_shift($response);

Expand Down Expand Up @@ -330,8 +334,8 @@ public function move(string $source, string $destination, Config $config): void
}

$this->createParentDirFor($destination);
$location = $this->prefixer->prefixPath($this->encodePath($source));
$newLocation = $this->prefixer->prefixPath($this->encodePath($destination));
$location = $this->encodePath($this->prefixer->prefixPath($source));
$newLocation = $this->encodePath($this->prefixer->prefixPath($destination));

try {
$response = $this->client->request('MOVE', '/' . ltrim($location, '/'), null, [
Expand Down Expand Up @@ -367,8 +371,8 @@ public function copy(string $source, string $destination, Config $config): void
}

$this->createParentDirFor($destination);
$location = $this->prefixer->prefixPath($this->encodePath($source));
$newLocation = $this->prefixer->prefixPath($this->encodePath($destination));
$location = $this->encodePath($this->prefixer->prefixPath($source));
$newLocation = $this->encodePath($this->prefixer->prefixPath($destination));

try {
$response = $this->client->request('COPY', '/' . ltrim($location, '/'), null, [
Expand Down Expand Up @@ -410,10 +414,6 @@ private function createParentDirFor(string $path): void
{
$dirname = dirname($path);

if ($dirname === '.' || $dirname === '') {
return;
}

if ($this->directoryExists($dirname)) {
return;
}
Expand Down