summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib/helper.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/lib/helper.php')
-rw-r--r--apps/files_sharing/lib/helper.php22
1 files changed, 22 insertions, 0 deletions
diff --git a/apps/files_sharing/lib/helper.php b/apps/files_sharing/lib/helper.php
index 71b496ab944..49546f012a6 100644
--- a/apps/files_sharing/lib/helper.php
+++ b/apps/files_sharing/lib/helper.php
@@ -180,4 +180,26 @@ class Helper {
return $relPath;
}
+
+ /**
+ * check if file name already exists and generate unique target
+ *
+ * @param string $path
+ * @param array $excludeList
+ * @param \OC\Files\View $view
+ * @return string $path
+ */
+ public static function generateUniqueTarget($path, $excludeList, $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 = \OC\Files\Filesystem::normalizePath($dir . '/' . $name . ' ('.$i.')' . $ext);
+ $i++;
+ }
+
+ return $path;
+ }
}