summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2014-04-08 12:29:47 +0200
committerBjoern Schiessle <schiessle@owncloud.com>2014-04-23 12:54:25 +0200
commit6b19482f3e1d97aab63c6c870c53a27d5e5a8524 (patch)
tree5e6ab2f5021e78880922b4ba3caad2f0220c34e1 /apps/files_sharing
parentc4e0fb75a4e8c9cb133ce79b6a737b2ba7b161df (diff)
downloadnextcloud-server-6b19482f3e1d97aab63c6c870c53a27d5e5a8524.tar.gz
nextcloud-server-6b19482f3e1d97aab63c6c870c53a27d5e5a8524.zip
generate unique target name
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/lib/share/file.php44
1 files changed, 29 insertions, 15 deletions
diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php
index f9f3211bd82..c628b11589d 100644
--- a/apps/files_sharing/lib/share/file.php
+++ b/apps/files_sharing/lib/share/file.php
@@ -28,6 +28,7 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
const FORMAT_OPENDIR = 3;
const FORMAT_GET_ALL = 4;
const FORMAT_PERMISSIONS = 5;
+ const FORMAT_TARGET_NAMES = 6;
private $path;
@@ -50,24 +51,31 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
return false;
}
+ /**
+ * @brief create unique target
+ * @param string $filePath
+ * @param string $shareWith
+ * @param string $exclude
+ * @return string
+ */
public function generateTarget($filePath, $shareWith, $exclude = null) {
$target = '/'.basename($filePath);
- if (isset($exclude)) {
- if ($pos = strrpos($target, '.')) {
- $name = substr($target, 0, $pos);
- $ext = substr($target, $pos);
- } else {
- $name = $target;
- $ext = '';
- }
- $i = 2;
- $append = '';
- while (in_array($name.$append.$ext, $exclude)) {
- $append = ' ('.$i.')';
- $i++;
- }
- $target = $name.$append.$ext;
+ \OC\Files\Filesystem::initMountPoints($shareWith);
+ $view = new \OC\Files\View('/' . $shareWith . '/files');
+ $excludeList = \OCP\Share::getItemsSharedWithUser('file', $shareWith, self::FORMAT_TARGET_NAMES);
+ if (is_array($exclude)) {
+ $excludeList = array_merge($excludeList, $exclude);
}
+
+ $pathinfo = pathinfo($target);
+ $ext = (isset($pathinfo['extension'])) ? '.'.$pathinfo['extension'] : '';
+ $name = $pathinfo['filename'];
+ $i = 2;
+ while ($view->file_exists($target) || in_array($target, $excludeList)) {
+ $target = '/' . $name . ' ('.$i.')' . $ext;
+ $i++;
+ }
+
return $target;
}
@@ -127,6 +135,12 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
$filePermissions[$item['file_source']] = $item['permissions'];
}
return $filePermissions;
+ } else if ($format === self::FORMAT_TARGET_NAMES) {
+ $targets = array();
+ foreach ($items as $item) {
+ $targets[] = $item['file_target'];
+ }
+ return $targets;
}
return array();
}