Skip to content

Commit

Permalink
feat: made rename more predictable
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianKoehnen committed Nov 2, 2022
1 parent 4e349ff commit 99e639a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ public function getFileHandle()

public function rename(string $newPath): bool
{
if ('/' !== $newPath[0]) {
$newPath = dirname($this->filePath).'/'.$newPath;
}

fclose($this->fileHandle);

$success = rename($this->filePath, $newPath);
$this->openStream($newPath, $this->mode);

Expand Down
5 changes: 5 additions & 0 deletions src/Remote/SftpFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ protected function openStream(string $filePath, string $mode): void

public function rename(string $newPath): bool
{
if ('/' !== $newPath[0]) {
$newPath = dirname($this->filePath).'/'.$newPath;
}

fclose($this->fileHandle);

$success = $this->sftp->rename($this->filePath, $newPath);
$this->openStream($newPath, $this->mode);

Expand Down

0 comments on commit 99e639a

Please sign in to comment.