Skip to content

Commit

Permalink
chore: Remove deprecated Share_Helper::generateTarget $exclude pa…
Browse files Browse the repository at this point in the history
…rameter

Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Sep 19, 2024
1 parent ed776bb commit 777e349
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
7 changes: 3 additions & 4 deletions apps/files_sharing/lib/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ public static function registerHooks() {
* check if file name already exists and generate unique target
*
* @param string $path
* @param array $excludeList
* @param View $view
* @return string $path
*/
public static function generateUniqueTarget($path, $excludeList, $view) {
public static function generateUniqueTarget($path, $view) {
$pathinfo = pathinfo($path);
$ext = isset($pathinfo['extension']) ? '.' . $pathinfo['extension'] : '';
$name = $pathinfo['filename'];
$dir = $pathinfo['dirname'];
$i = 2;
while ($view->file_exists($path) || in_array($path, $excludeList)) {
$path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext);
while ($view->file_exists($path)) {
$path = Filesystem::normalizePath($dir . '/' . $name . ' ('.$i.')' . $ext);
$i++;
}

Expand Down
12 changes: 2 additions & 10 deletions apps/files_sharing/lib/ShareBackend/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,12 @@ public function getFilePath($itemSource, $uidOwner) {
*
* @param string $itemSource
* @param string $shareWith
* @param array $exclude (optional)
* @return string
*/
public function generateTarget($itemSource, $shareWith, $exclude = null) {
public function generateTarget($itemSource, $shareWith) {

Check notice

Code scanning / Psalm

MoreSpecificImplementedParamType Note

Argument 2 of OCA\Files_Sharing\ShareBackend\File::generateTarget has the more specific type 'string', expecting 'false|string' as defined by OCP\Share_Backend::generateTarget
$shareFolder = \OCA\Files_Sharing\Helper::getShareFolder();
$target = \OC\Files\Filesystem::normalizePath($shareFolder . '/' . basename($itemSource));

// for group shares we return the target right away
if ($shareWith === false) {
return $target;
}

\OC\Files\Filesystem::initMountPoints($shareWith);
$view = new \OC\Files\View('/' . $shareWith . '/files');

Expand All @@ -91,9 +85,7 @@ public function generateTarget($itemSource, $shareWith, $exclude = null) {
}
}

$excludeList = is_array($exclude) ? $exclude : [];

return \OCA\Files_Sharing\Helper::generateUniqueTarget($target, $excludeList, $view);
return \OCA\Files_Sharing\Helper::generateUniqueTarget($target, $view);
}

public function formatItems($items, $format, $parameters = null) {
Expand Down
4 changes: 2 additions & 2 deletions lib/public/Share_Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ public function isValidSource($itemSource, $uidOwner);
* Get a unique name of the item for the specified user
* @param string $itemSource
* @param string|false $shareWith User the item is being shared with
* @param array|null $exclude List of similar item names already existing as shared items @deprecated 7.0.0
* @return string Target name
*
* This function needs to verify that the user does not already have an item with this name.
* If it does generate a new name e.g. name_#
* @since 5.0.0
* @deprecated 31.0.0
*/
public function generateTarget($itemSource, $shareWith, $exclude = null);
public function generateTarget($itemSource, $shareWith);

/**
* Converts the shared item sources back into the item in the specified format
Expand Down

0 comments on commit 777e349

Please sign in to comment.