diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2013-07-30 00:34:36 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2013-07-30 00:34:36 +0200 |
commit | 7425efade78a04f20cb3cc83f964c6a00094b6ce (patch) | |
tree | 967aa50e8873c88f0adf6f91d0285ab1c54b7189 /lib/helper.php | |
parent | b4a523927823ab8bc80c5f1fc0d5bd5ef61f8eb8 (diff) | |
parent | 7c6246fa451c4646dfaa1396dd37e0b3eb9706ba (diff) | |
download | nextcloud-server-7425efade78a04f20cb3cc83f964c6a00094b6ce.tar.gz nextcloud-server-7425efade78a04f20cb3cc83f964c6a00094b6ce.zip |
Merge branch 'master' into oc_preview
Conflicts:
3rdparty
lib/template.php
Diffstat (limited to 'lib/helper.php')
-rw-r--r-- | lib/helper.php | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/lib/helper.php b/lib/helper.php index 0853c792750..460e5679b02 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -176,8 +176,7 @@ class OC_Helper { }elseif( file_exists( OC::$SERVERROOT."/core/img/$image" )) { return OC::$WEBROOT."/core/img/$image"; }else{ - echo('image not found: image:'.$image.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); - die(); + throw new RuntimeException('image not found: image:'.$image.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); } } @@ -651,6 +650,18 @@ class OC_Helper { * @return string */ public static function buildNotExistingFileName($path, $filename) { + $view = \OC\Files\Filesystem::getView(); + return self::buildNotExistingFileNameForView($path, $filename, $view); + } + + /** + * Adds a suffix to the name in case the file exists + * + * @param $path + * @param $filename + * @return string + */ + public static function buildNotExistingFileNameForView($path, $filename, \OC\Files\View $view) { if($path==='/') { $path=''; } @@ -663,11 +674,27 @@ class OC_Helper { } $newpath = $path . '/' . $filename; - $counter = 2; - while (\OC\Files\Filesystem::file_exists($newpath)) { - $newname = $name . ' (' . $counter . ')' . $ext; - $newpath = $path . '/' . $newname; - $counter++; + if ($view->file_exists($newpath)) { + if(preg_match_all('/\((\d+)\)/', $name, $matches, PREG_OFFSET_CAPTURE)) { + //Replace the last "(number)" with "(number+1)" + $last_match = count($matches[0])-1; + $counter = $matches[1][$last_match][0]+1; + $offset = $matches[0][$last_match][1]; + $match_length = strlen($matches[0][$last_match][0]); + } else { + $counter = 2; + $offset = false; + } + do { + if($offset) { + //Replace the last "(number)" with "(number+1)" + $newname = substr_replace($name, '('.$counter.')', $offset, $match_length); + } else { + $newname = $name . ' (' . $counter . ')'; + } + $newpath = $path . '/' . $newname . $ext; + $counter++; + } while ($view->file_exists($newpath)); } return $newpath; |