Code Duplication    Length = 21-24 lines in 3 locations

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

apps/files_trashbin/lib/Trashbin.php 1 location

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

apps/files_versions/lib/Storage.php 1 location

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