From be4e92130683e90f98ddcb268067951d1fc32153 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 23 Nov 2017 12:35:47 +0100 Subject: [PATCH] Use basename() instead of self implementation Signed-off-by: Morris Jobke --- lib/private/Files/Cache/Cache.php | 4 ++-- lib/private/legacy/util.php | 10 ---------- tests/lib/UtilTest.php | 18 ------------------ 3 files changed, 2 insertions(+), 30 deletions(-) diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 93af3fcf6b617..cf017c73960c5 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -259,7 +259,7 @@ public function insert($file, array $data) { $data['path'] = $file; $data['parent'] = $this->getParentId($file); - $data['name'] = \OC_Util::basename($file); + $data['name'] = basename($file); list($queryParts, $params) = $this->buildParts($data); $queryParts[] = '`storage`'; @@ -551,7 +551,7 @@ public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { } $sql = 'UPDATE `*PREFIX*filecache` SET `storage` = ?, `path` = ?, `path_hash` = ?, `name` = ?, `parent` = ? WHERE `fileid` = ?'; - $this->connection->executeQuery($sql, array($targetStorageId, $targetPath, md5($targetPath), \OC_Util::basename($targetPath), $newParentId, $sourceId)); + $this->connection->executeQuery($sql, array($targetStorageId, $targetPath, md5($targetPath), basename($targetPath), $newParentId, $sourceId)); $this->connection->commit(); } else { $this->moveFromCacheFallback($sourceCache, $sourcePath, $targetPath); diff --git a/lib/private/legacy/util.php b/lib/private/legacy/util.php index 2610ec3a7b6c0..1e9090960c139 100644 --- a/lib/private/legacy/util.php +++ b/lib/private/legacy/util.php @@ -1407,16 +1407,6 @@ public static function normalizeUnicode($value) { return $normalizedValue; } - /** - * @param boolean|string $file - * @return string - */ - public static function basename($file) { - $file = rtrim($file, '/'); - $t = explode('/', $file); - return array_pop($t); - } - /** * A human readable string is generated based on version and build number * diff --git a/tests/lib/UtilTest.php b/tests/lib/UtilTest.php index 49dc4ddebb1d3..16d03b049fe80 100644 --- a/tests/lib/UtilTest.php +++ b/tests/lib/UtilTest.php @@ -177,24 +177,6 @@ function testGetInstanceIdGeneratesValidId() { $this->assertSame(1, $matchesRegex); } - /** - * @dataProvider baseNameProvider - */ - public function testBaseName($expected, $file) { - $base = \OC_Util::basename($file); - $this->assertEquals($expected, $base); - } - - public function baseNameProvider() { - return array( - array('public_html', '/home/user/public_html/'), - array('public_html', '/home/user/public_html'), - array('', '/'), - array('public_html', 'public_html'), - array('442aa682de2a64db1e010f50e60fd9c9', 'local::C:\Users\ADMINI~1\AppData\Local\Temp\2/442aa682de2a64db1e010f50e60fd9c9/') - ); - } - /** * @dataProvider filenameValidationProvider */