Code Duplication    Length = 21-24 lines in 2 locations

apps/files_sharing/lib/Helper.php 1 location

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

apps/files_versions/lib/Storage.php 1 location

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