Skip to content

Commit

Permalink
Only overwrite files, not directories
Browse files Browse the repository at this point in the history
  • Loading branch information
matt committed Aug 15, 2023
1 parent 0993e28 commit 7f5a780
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 42 deletions.
5 changes: 0 additions & 5 deletions src/PhpseclibV3/SftpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,6 @@ public function move(string $source, string $destination, Config $config): void
if ($connection->rename($sourceLocation, $destinationLocation)) {
return;
}
} elseif ($connection->is_dir($destinationLocation)) {
$this->deleteDirectory($destination);
if ($connection->rename($sourceLocation, $destinationLocation)) {
return;
}
}

throw UnableToMoveFile::fromLocationTo($source, $destination);
Expand Down
37 changes: 0 additions & 37 deletions src/PhpseclibV3/SftpAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,43 +247,6 @@ public function moving_a_file_and_overwriting(): void
});
}

/**
* @test
* @fixme Move to FilesystemAdapterTestCase once all adapters pass
*/
public function moving_a_directory_and_overwriting(): void
{
$this->runScenario(function() {
$adapter = $this->adapter();
$config = new Config();

$adapter->createDirectory('move_and_overwrite_source', $config);
$adapter->write('move_and_overwrite_source/a', 'a', $config);

$adapter->createDirectory('move_and_overwrite_target', $config);
$adapter->write('move_and_overwrite_target/b', 'b', $config);

$adapter->move('move_and_overwrite_source', 'move_and_overwrite_target', $config);

$this->assertFalse(
$adapter->directoryExists('move_and_overwrite_source'),
'Source directory should not exist'
);
$this->assertTrue(
$adapter->directoryExists('move_and_overwrite_target'),
'Target directory should exist'
);
$this->assertTrue(
$adapter->fileExists('move_and_overwrite_target/a'),
'Source files not moved'
);
$this->assertFalse(
$adapter->fileExists('move_and_overwrite_target/b'),
'Target files not deleted'
);
});
}

private static function connectionProvider(): ConnectionProvider
{
if ( ! static::$connectionProvider instanceof ConnectionProvider) {
Expand Down

0 comments on commit 7f5a780

Please sign in to comment.