Code Duplication    Length = 21-24 lines in 3 locations

apps/files_trashbin/lib/Trashbin.php 1 location

@@ 81-101 (lines=21) @@
78
	 * @return array
79
	 * @throws \OC\User\NoUserException
80
	 */
81
	public static function getUidAndFilename($filename) {
82
		$uid = Filesystem::getOwner($filename);
83
		$userManager = \OC::$server->getUserManager();
84
		// if the user with the UID doesn't exists, e.g. because the UID points
85
		// to a remote user with a federated cloud ID we use the current logged-in
86
		// user. We need a valid local user to move the file to the right trash bin
87
		if (!$userManager->userExists($uid)) {
88
			$uid = User::getUser();
89
		}
90
		Filesystem::initMountPoints($uid);
91
		if ($uid != User::getUser()) {
92
			$info = Filesystem::getFileInfo($filename);
93
			$ownerView = new View('/' . $uid . '/files');
94
			try {
95
				$filename = $ownerView->getPath($info['fileid']);
96
			} catch (NotFoundException $e) {
97
				$filename = null;
98
			}
99
		}
100
		return [$uid, $filename];
101
	}
102
103
	/**
104
	 * get original location of files for user

apps/files_versions/lib/Storage.php 1 location

@@ 92-115 (lines=24) @@
89
	 * @return array
90
	 * @throws \OC\User\NoUserException
91
	 */
92
	public static function getUidAndFilename($filename) {
93
		$uid = Filesystem::getOwner($filename);
94
		$userManager = \OC::$server->getUserManager();
95
		// if the user with the UID doesn't exists, e.g. because the UID points
96
		// to a remote user with a federated cloud ID we use the current logged-in
97
		// user. We need a valid local user to create the versions
98
		if (!$userManager->userExists($uid)) {
99
			$uid = User::getUser();
100
		}
101
		Filesystem::initMountPoints($uid);
102
		if ( $uid != User::getUser() ) {
103
			$info = Filesystem::getFileInfo($filename);
104
			$ownerView = new View('/'.$uid.'/files');
105
			try {
106
				$filename = $ownerView->getPath($info['fileid']);
107
				// make sure that the file name doesn't end with a trailing slash
108
				// can for example happen single files shared across servers
109
				$filename = rtrim($filename, '/');
110
			} catch (NotFoundException $e) {
111
				$filename = null;
112
			}
113
		}
114
		return [$uid, $filename];
115
	}
116
117
	/**
118
	 * Remember the owner and the owner path of the source file

apps/files_sharing/lib/Helper.php 1 location

@@ 177-197 (lines=21) @@
174
	 * @return array
175
	 * @throws \OC\User\NoUserException
176
	 */
177
	public static function getUidAndFilename($filename) {
178
		$uid = Filesystem::getOwner($filename);
179
		$userManager = \OC::$server->getUserManager();
180
		// if the user with the UID doesn't exists, e.g. because the UID points
181
		// to a remote user with a federated cloud ID we use the current logged-in
182
		// user. We need a valid local user to create the share
183
		if (!$userManager->userExists($uid)) {
184
			$uid = User::getUser();
185
		}
186
		Filesystem::initMountPoints($uid);
187
		if ( $uid != User::getUser() ) {
188
			$info = Filesystem::getFileInfo($filename);
189
			$ownerView = new View('/'.$uid.'/files');
190
			try {
191
				$filename = $ownerView->getPath($info['fileid']);
192
			} catch (NotFoundException $e) {
193
				$filename = null;
194
			}
195
		}
196
		return [$uid, $filename];
197
	}
198
199
	/**
200
	 * Format a path to be relative to the /user/files/ directory