Skip to content

Commit

Permalink
Merge pull request #1533 from mtorromeo/webdav-prefix-fixes
Browse files Browse the repository at this point in the history
Fix prefix-related issues in WebDAV adapter
  • Loading branch information
frankdejonge authored Sep 9, 2022
2 parents 1f080e9 + c1da0a3 commit 4d1c3b7
Showing 1 changed file with 18 additions and 18 deletions.
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

0 comments on commit 4d1c3b7

Please sign in to comment.