Completed
Pull Request — master (#4449)
by Stefan
22:56
created
lib/public/Files/StorageAuthException.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,6 @@
 block discarded – undo
30 30
 	 * StorageAuthException constructor.
31 31
 	 *
32 32
 	 * @param string $message
33
-	 * @param int $code
34 33
 	 * @param \Exception $previous
35 34
 	 * @since 9.0.0
36 35
 	 */
Please login to merge, or discard this patch.
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -27,16 +27,16 @@
 block discarded – undo
27 27
  */
28 28
 class StorageAuthException extends StorageNotAvailableException {
29 29
 
30
-	/**
31
-	 * StorageAuthException constructor.
32
-	 *
33
-	 * @param string $message
34
-	 * @param int $code
35
-	 * @param \Exception $previous
36
-	 * @since 9.0.0
37
-	 */
38
-	public function __construct($message = '', \Exception $previous = null) {
39
-		$l = \OC::$server->getL10N('core');
40
-		parent::__construct($l->t('Storage unauthorized. %s', $message), self::STATUS_UNAUTHORIZED, $previous);
41
-	}
30
+    /**
31
+     * StorageAuthException constructor.
32
+     *
33
+     * @param string $message
34
+     * @param int $code
35
+     * @param \Exception $previous
36
+     * @since 9.0.0
37
+     */
38
+    public function __construct($message = '', \Exception $previous = null) {
39
+        $l = \OC::$server->getL10N('core');
40
+        parent::__construct($l->t('Storage unauthorized. %s', $message), self::STATUS_UNAUTHORIZED, $previous);
41
+    }
42 42
 }
Please login to merge, or discard this patch.
lib/public/Files/StorageBadConfigException.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,6 @@
 block discarded – undo
30 30
 	 * ExtStorageBadConfigException constructor.
31 31
 	 *
32 32
 	 * @param string $message
33
-	 * @param int $code
34 33
 	 * @param \Exception $previous
35 34
 	 * @since 9.0.0
36 35
 	 */
Please login to merge, or discard this patch.
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -27,17 +27,17 @@
 block discarded – undo
27 27
  */
28 28
 class StorageBadConfigException extends StorageNotAvailableException {
29 29
 
30
-	/**
31
-	 * ExtStorageBadConfigException constructor.
32
-	 *
33
-	 * @param string $message
34
-	 * @param int $code
35
-	 * @param \Exception $previous
36
-	 * @since 9.0.0
37
-	 */
38
-	public function __construct($message = '', \Exception $previous = null) {
39
-		$l = \OC::$server->getL10N('core');
40
-		parent::__construct($l->t('Storage incomplete configuration. %s', $message), self::STATUS_INCOMPLETE_CONF, $previous);
41
-	}
30
+    /**
31
+     * ExtStorageBadConfigException constructor.
32
+     *
33
+     * @param string $message
34
+     * @param int $code
35
+     * @param \Exception $previous
36
+     * @since 9.0.0
37
+     */
38
+    public function __construct($message = '', \Exception $previous = null) {
39
+        $l = \OC::$server->getL10N('core');
40
+        parent::__construct($l->t('Storage incomplete configuration. %s', $message), self::STATUS_INCOMPLETE_CONF, $previous);
41
+    }
42 42
 
43 43
 }
Please login to merge, or discard this patch.
lib/public/Files/StorageConnectionException.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,6 @@
 block discarded – undo
30 30
 	 * StorageConnectionException constructor.
31 31
 	 *
32 32
 	 * @param string $message
33
-	 * @param int $code
34 33
 	 * @param \Exception $previous
35 34
 	 * @since 9.0.0
36 35
 	 */
Please login to merge, or discard this patch.
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -27,16 +27,16 @@
 block discarded – undo
27 27
  */
28 28
 class StorageConnectionException extends StorageNotAvailableException {
29 29
 
30
-	/**
31
-	 * StorageConnectionException constructor.
32
-	 *
33
-	 * @param string $message
34
-	 * @param int $code
35
-	 * @param \Exception $previous
36
-	 * @since 9.0.0
37
-	 */
38
-	public function __construct($message = '', \Exception $previous = null) {
39
-		$l = \OC::$server->getL10N('core');
40
-		parent::__construct($l->t('Storage connection error. %s', $message), self::STATUS_NETWORK_ERROR, $previous);
41
-	}
30
+    /**
31
+     * StorageConnectionException constructor.
32
+     *
33
+     * @param string $message
34
+     * @param int $code
35
+     * @param \Exception $previous
36
+     * @since 9.0.0
37
+     */
38
+    public function __construct($message = '', \Exception $previous = null) {
39
+        $l = \OC::$server->getL10N('core');
40
+        parent::__construct($l->t('Storage connection error. %s', $message), self::STATUS_NETWORK_ERROR, $previous);
41
+    }
42 42
 }
Please login to merge, or discard this patch.
lib/public/Files/StorageTimeoutException.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,6 @@
 block discarded – undo
30 30
 	 * StorageTimeoutException constructor.
31 31
 	 *
32 32
 	 * @param string $message
33
-	 * @param int $code
34 33
 	 * @param \Exception $previous
35 34
 	 * @since 9.0.0
36 35
 	 */
Please login to merge, or discard this patch.
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -27,16 +27,16 @@
 block discarded – undo
27 27
  */
28 28
 class StorageTimeoutException extends StorageNotAvailableException {
29 29
 
30
-	/**
31
-	 * StorageTimeoutException constructor.
32
-	 *
33
-	 * @param string $message
34
-	 * @param int $code
35
-	 * @param \Exception $previous
36
-	 * @since 9.0.0
37
-	 */
38
-	public function __construct($message = '', \Exception $previous = null) {
39
-		$l = \OC::$server->getL10N('core');
40
-		parent::__construct($l->t('Storage connection timeout. %s', $message), self::STATUS_TIMEOUT, $previous);
41
-	}
30
+    /**
31
+     * StorageTimeoutException constructor.
32
+     *
33
+     * @param string $message
34
+     * @param int $code
35
+     * @param \Exception $previous
36
+     * @since 9.0.0
37
+     */
38
+    public function __construct($message = '', \Exception $previous = null) {
39
+        $l = \OC::$server->getL10N('core');
40
+        parent::__construct($l->t('Storage connection timeout. %s', $message), self::STATUS_TIMEOUT, $previous);
41
+    }
42 42
 }
Please login to merge, or discard this patch.
lib/public/Migration/IOutput.php 2 patches
Doc Comments   +5 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,18 +32,21 @@  discard block
 block discarded – undo
32 32
 	/**
33 33
 	 * @param string $message
34 34
 	 * @since 9.1.0
35
+	 * @return void
35 36
 	 */
36 37
 	public function info($message);
37 38
 
38 39
 	/**
39 40
 	 * @param string $message
40 41
 	 * @since 9.1.0
42
+	 * @return void
41 43
 	 */
42 44
 	public function warning($message);
43 45
 
44 46
 	/**
45 47
 	 * @param int $max
46 48
 	 * @since 9.1.0
49
+	 * @return void
47 50
 	 */
48 51
 	public function startProgress($max = 0);
49 52
 
@@ -51,12 +54,13 @@  discard block
 block discarded – undo
51 54
 	 * @param int $step
52 55
 	 * @param string $description
53 56
 	 * @since 9.1.0
57
+	 * @return void
54 58
 	 */
55 59
 	public function advance($step = 1, $description = '');
56 60
 
57 61
 	/**
58
-	 * @param int $max
59 62
 	 * @since 9.1.0
63
+	 * @return void
60 64
 	 */
61 65
 	public function finishProgress();
62 66
 
Please login to merge, or discard this patch.
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -30,35 +30,35 @@
 block discarded – undo
30 30
  */
31 31
 interface IOutput {
32 32
 
33
-	/**
34
-	 * @param string $message
35
-	 * @since 9.1.0
36
-	 */
37
-	public function info($message);
33
+    /**
34
+     * @param string $message
35
+     * @since 9.1.0
36
+     */
37
+    public function info($message);
38 38
 
39
-	/**
40
-	 * @param string $message
41
-	 * @since 9.1.0
42
-	 */
43
-	public function warning($message);
39
+    /**
40
+     * @param string $message
41
+     * @since 9.1.0
42
+     */
43
+    public function warning($message);
44 44
 
45
-	/**
46
-	 * @param int $max
47
-	 * @since 9.1.0
48
-	 */
49
-	public function startProgress($max = 0);
45
+    /**
46
+     * @param int $max
47
+     * @since 9.1.0
48
+     */
49
+    public function startProgress($max = 0);
50 50
 
51
-	/**
52
-	 * @param int $step
53
-	 * @param string $description
54
-	 * @since 9.1.0
55
-	 */
56
-	public function advance($step = 1, $description = '');
51
+    /**
52
+     * @param int $step
53
+     * @param string $description
54
+     * @since 9.1.0
55
+     */
56
+    public function advance($step = 1, $description = '');
57 57
 
58
-	/**
59
-	 * @param int $max
60
-	 * @since 9.1.0
61
-	 */
62
-	public function finishProgress();
58
+    /**
59
+     * @param int $max
60
+     * @since 9.1.0
61
+     */
62
+    public function finishProgress();
63 63
 
64 64
 }
Please login to merge, or discard this patch.
lib/public/SystemTag/ISystemTagManager.php 2 patches
Doc Comments   +7 added lines, -4 removed lines patch added patch discarded remove patch
@@ -102,17 +102,19 @@  discard block
 block discarded – undo
102 102
 	 * with the same attributes
103 103
 	 *
104 104
 	 * @since 9.0.0
105
+	 * @return void
105 106
 	 */
106 107
 	public function updateTag($tagId, $newName, $userVisible, $userAssignable);
107 108
 
108 109
 	/**
109 110
 	 * Delete the given tags from the database and all their relationships.
110 111
 	 *
111
-	 * @param string|array $tagIds array of tag ids
112
+	 * @param string $tagIds array of tag ids
112 113
 	 *
113 114
 	 * @throws \OCP\SystemTag\TagNotFoundException if at least one tag did not exist
114 115
 	 *
115 116
 	 * @since 9.0.0
117
+	 * @return void
116 118
 	 */
117 119
 	public function deleteTags($tagIds);
118 120
 
@@ -123,7 +125,7 @@  discard block
 block discarded – undo
123 125
 	 * @param ISystemTag $tag tag to check permission for
124 126
 	 * @param IUser $user user to check permission for
125 127
 	 *
126
-	 * @return true if the user is allowed to assign/unassign the tag, false otherwise
128
+	 * @return boolean if the user is allowed to assign/unassign the tag, false otherwise
127 129
 	 *
128 130
 	 * @since 9.1.0
129 131
 	 */
@@ -133,9 +135,9 @@  discard block
 block discarded – undo
133 135
 	 * Checks whether the given user is allowed to see the tag with the given id.
134 136
 	 *
135 137
 	 * @param ISystemTag $tag tag to check permission for
136
-	 * @param IUser $user user to check permission for
138
+	 * @param IUser $userId user to check permission for
137 139
 	 *
138
-	 * @return true if the user can see the tag, false otherwise
140
+	 * @return boolean if the user can see the tag, false otherwise
139 141
 	 *
140 142
 	 * @since 9.1.0
141 143
 	 */
@@ -148,6 +150,7 @@  discard block
 block discarded – undo
148 150
 	 * @param string[] $groupIds group ids of groups that can assign/unassign the tag
149 151
 	 *
150 152
 	 * @since 9.1.0
153
+	 * @return void
151 154
 	 */
152 155
 	public function setTagGroups(ISystemTag $tag, $groupIds);
153 156
 
Please login to merge, or discard this patch.
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -33,133 +33,133 @@
 block discarded – undo
33 33
  */
34 34
 interface ISystemTagManager {
35 35
 
36
-	/**
37
-	 * Returns the tag objects matching the given tag ids.
38
-	 *
39
-	 * @param array|string $tagIds id or array of unique ids of the tag to retrieve
40
-	 *
41
-	 * @return \OCP\SystemTag\ISystemTag[] array of system tags with tag id as key
42
-	 *
43
-	 * @throws \InvalidArgumentException if at least one given tag ids is invalid (string instead of integer, etc.)
44
-	 * @throws \OCP\SystemTag\TagNotFoundException if at least one given tag ids did no exist
45
-	 * 			The message contains a json_encoded array of the ids that could not be found
46
-	 *
47
-	 * @since 9.0.0
48
-	 */
49
-	public function getTagsByIds($tagIds);
36
+    /**
37
+     * Returns the tag objects matching the given tag ids.
38
+     *
39
+     * @param array|string $tagIds id or array of unique ids of the tag to retrieve
40
+     *
41
+     * @return \OCP\SystemTag\ISystemTag[] array of system tags with tag id as key
42
+     *
43
+     * @throws \InvalidArgumentException if at least one given tag ids is invalid (string instead of integer, etc.)
44
+     * @throws \OCP\SystemTag\TagNotFoundException if at least one given tag ids did no exist
45
+     * 			The message contains a json_encoded array of the ids that could not be found
46
+     *
47
+     * @since 9.0.0
48
+     */
49
+    public function getTagsByIds($tagIds);
50 50
 
51
-	/**
52
-	 * Returns the tag object matching the given attributes.
53
-	 *
54
-	 * @param string $tagName tag name
55
-	 * @param bool $userVisible whether the tag is visible by users
56
-	 * @param bool $userAssignable whether the tag is assignable by users
57
-	 *
58
-	 * @return \OCP\SystemTag\ISystemTag system tag
59
-	 *
60
-	 * @throws \OCP\SystemTag\TagNotFoundException if tag does not exist
61
-	 *
62
-	 * @since 9.0.0
63
-	 */
64
-	public function getTag($tagName, $userVisible, $userAssignable);
51
+    /**
52
+     * Returns the tag object matching the given attributes.
53
+     *
54
+     * @param string $tagName tag name
55
+     * @param bool $userVisible whether the tag is visible by users
56
+     * @param bool $userAssignable whether the tag is assignable by users
57
+     *
58
+     * @return \OCP\SystemTag\ISystemTag system tag
59
+     *
60
+     * @throws \OCP\SystemTag\TagNotFoundException if tag does not exist
61
+     *
62
+     * @since 9.0.0
63
+     */
64
+    public function getTag($tagName, $userVisible, $userAssignable);
65 65
 
66
-	/**
67
-	 * Creates the tag object using the given attributes.
68
-	 *
69
-	 * @param string $tagName tag name
70
-	 * @param bool $userVisible whether the tag is visible by users
71
-	 * @param bool $userAssignable whether the tag is assignable by users
72
-	 *
73
-	 * @return \OCP\SystemTag\ISystemTag system tag
74
-	 *
75
-	 * @throws \OCP\SystemTag\TagAlreadyExistsException if tag already exists
76
-	 *
77
-	 * @since 9.0.0
78
-	 */
79
-	public function createTag($tagName, $userVisible, $userAssignable);
66
+    /**
67
+     * Creates the tag object using the given attributes.
68
+     *
69
+     * @param string $tagName tag name
70
+     * @param bool $userVisible whether the tag is visible by users
71
+     * @param bool $userAssignable whether the tag is assignable by users
72
+     *
73
+     * @return \OCP\SystemTag\ISystemTag system tag
74
+     *
75
+     * @throws \OCP\SystemTag\TagAlreadyExistsException if tag already exists
76
+     *
77
+     * @since 9.0.0
78
+     */
79
+    public function createTag($tagName, $userVisible, $userAssignable);
80 80
 
81
-	/**
82
-	 * Returns all known tags, optionally filtered by visibility.
83
-	 *
84
-	 * @param bool|null $visibilityFilter filter by visibility if non-null
85
-	 * @param string $nameSearchPattern optional search pattern for the tag name
86
-	 *
87
-	 * @return \OCP\SystemTag\ISystemTag[] array of system tags or empty array if none found
88
-	 *
89
-	 * @since 9.0.0
90
-	 */
91
-	public function getAllTags($visibilityFilter = null, $nameSearchPattern = null);
81
+    /**
82
+     * Returns all known tags, optionally filtered by visibility.
83
+     *
84
+     * @param bool|null $visibilityFilter filter by visibility if non-null
85
+     * @param string $nameSearchPattern optional search pattern for the tag name
86
+     *
87
+     * @return \OCP\SystemTag\ISystemTag[] array of system tags or empty array if none found
88
+     *
89
+     * @since 9.0.0
90
+     */
91
+    public function getAllTags($visibilityFilter = null, $nameSearchPattern = null);
92 92
 
93
-	/**
94
-	 * Updates the given tag
95
-	 *
96
-	 * @param string $tagId tag id
97
-	 * @param string $newName the new tag name
98
-	 * @param bool $userVisible whether the tag is visible by users
99
-	 * @param bool $userAssignable whether the tag is assignable by users
100
-	 *
101
-	 * @throws \OCP\SystemTag\TagNotFoundException if tag with the given id does not exist
102
-	 * @throws \OCP\SystemTag\TagAlreadyExistsException if there is already another tag
103
-	 * with the same attributes
104
-	 *
105
-	 * @since 9.0.0
106
-	 */
107
-	public function updateTag($tagId, $newName, $userVisible, $userAssignable);
93
+    /**
94
+     * Updates the given tag
95
+     *
96
+     * @param string $tagId tag id
97
+     * @param string $newName the new tag name
98
+     * @param bool $userVisible whether the tag is visible by users
99
+     * @param bool $userAssignable whether the tag is assignable by users
100
+     *
101
+     * @throws \OCP\SystemTag\TagNotFoundException if tag with the given id does not exist
102
+     * @throws \OCP\SystemTag\TagAlreadyExistsException if there is already another tag
103
+     * with the same attributes
104
+     *
105
+     * @since 9.0.0
106
+     */
107
+    public function updateTag($tagId, $newName, $userVisible, $userAssignable);
108 108
 
109
-	/**
110
-	 * Delete the given tags from the database and all their relationships.
111
-	 *
112
-	 * @param string|array $tagIds array of tag ids
113
-	 *
114
-	 * @throws \OCP\SystemTag\TagNotFoundException if at least one tag did not exist
115
-	 *
116
-	 * @since 9.0.0
117
-	 */
118
-	public function deleteTags($tagIds);
109
+    /**
110
+     * Delete the given tags from the database and all their relationships.
111
+     *
112
+     * @param string|array $tagIds array of tag ids
113
+     *
114
+     * @throws \OCP\SystemTag\TagNotFoundException if at least one tag did not exist
115
+     *
116
+     * @since 9.0.0
117
+     */
118
+    public function deleteTags($tagIds);
119 119
 
120
-	/**
121
-	 * Checks whether the given user is allowed to assign/unassign the tag with the
122
-	 * given id.
123
-	 *
124
-	 * @param ISystemTag $tag tag to check permission for
125
-	 * @param IUser $user user to check permission for
126
-	 *
127
-	 * @return true if the user is allowed to assign/unassign the tag, false otherwise
128
-	 *
129
-	 * @since 9.1.0
130
-	 */
131
-	public function canUserAssignTag(ISystemTag $tag, IUser $user);
120
+    /**
121
+     * Checks whether the given user is allowed to assign/unassign the tag with the
122
+     * given id.
123
+     *
124
+     * @param ISystemTag $tag tag to check permission for
125
+     * @param IUser $user user to check permission for
126
+     *
127
+     * @return true if the user is allowed to assign/unassign the tag, false otherwise
128
+     *
129
+     * @since 9.1.0
130
+     */
131
+    public function canUserAssignTag(ISystemTag $tag, IUser $user);
132 132
 
133
-	/**
134
-	 * Checks whether the given user is allowed to see the tag with the given id.
135
-	 *
136
-	 * @param ISystemTag $tag tag to check permission for
137
-	 * @param IUser $user user to check permission for
138
-	 *
139
-	 * @return true if the user can see the tag, false otherwise
140
-	 *
141
-	 * @since 9.1.0
142
-	 */
143
-	public function canUserSeeTag(ISystemTag $tag, IUser $userId);
133
+    /**
134
+     * Checks whether the given user is allowed to see the tag with the given id.
135
+     *
136
+     * @param ISystemTag $tag tag to check permission for
137
+     * @param IUser $user user to check permission for
138
+     *
139
+     * @return true if the user can see the tag, false otherwise
140
+     *
141
+     * @since 9.1.0
142
+     */
143
+    public function canUserSeeTag(ISystemTag $tag, IUser $userId);
144 144
 
145
-	/**
146
-	 * Set groups that can assign a given tag.
147
-	 *
148
-	 * @param ISystemTag $tag tag for group assignment
149
-	 * @param string[] $groupIds group ids of groups that can assign/unassign the tag
150
-	 *
151
-	 * @since 9.1.0
152
-	 */
153
-	public function setTagGroups(ISystemTag $tag, $groupIds);
145
+    /**
146
+     * Set groups that can assign a given tag.
147
+     *
148
+     * @param ISystemTag $tag tag for group assignment
149
+     * @param string[] $groupIds group ids of groups that can assign/unassign the tag
150
+     *
151
+     * @since 9.1.0
152
+     */
153
+    public function setTagGroups(ISystemTag $tag, $groupIds);
154 154
 
155
-	/**
156
-	 * Get groups that can assign a given tag.
157
-	 *
158
-	 * @param ISystemTag $tag tag for group assignment
159
-	 *
160
-	 * @return string[] group ids of groups that can assign/unassign the tag
161
-	 *
162
-	 * @since 9.1.0
163
-	 */
164
-	public function getTagGroups(ISystemTag $tag);
155
+    /**
156
+     * Get groups that can assign a given tag.
157
+     *
158
+     * @param ISystemTag $tag tag for group assignment
159
+     *
160
+     * @return string[] group ids of groups that can assign/unassign the tag
161
+     *
162
+     * @since 9.1.0
163
+     */
164
+    public function getTagGroups(ISystemTag $tag);
165 165
 }
Please login to merge, or discard this patch.
lib/public/Template.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -100,8 +100,8 @@
 block discarded – undo
100 100
 /**
101 101
  * Return the relative date in relation to today. Returns something like "last hour" or "two month ago"
102 102
  * @param int $timestamp unix timestamp
103
- * @param boolean $dateOnly
104
- * @return \OC_L10N_String human readable interpretation of the timestamp
103
+ * @param integer $dateOnly
104
+ * @return string human readable interpretation of the timestamp
105 105
  *
106 106
  * @deprecated 8.0.0 Use \OCP\Template::relative_modified_date() instead
107 107
  */
Please login to merge, or discard this patch.
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
  * @deprecated 8.0.0 Use \OCP\Template::image_path() instead
51 51
  */
52 52
 function image_path( $app, $image ) {
53
-	return(\image_path( $app, $image ));
53
+    return(\image_path( $app, $image ));
54 54
 }
55 55
 
56 56
 
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
  * @deprecated 8.0.0 Use \OCP\Template::mimetype_icon() instead
62 62
  */
63 63
 function mimetype_icon( $mimetype ) {
64
-	return(\mimetype_icon( $mimetype ));
64
+    return(\mimetype_icon( $mimetype ));
65 65
 }
66 66
 
67 67
 /**
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
  * @deprecated 8.0.0 Use \OCP\Template::preview_icon() instead
72 72
  */
73 73
 function preview_icon( $path ) {
74
-	return(\preview_icon( $path ));
74
+    return(\preview_icon( $path ));
75 75
 }
76 76
 
77 77
 /**
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
  * @deprecated 8.0.0 Use \OCP\Template::publicPreview_icon() instead
84 84
  */
85 85
 function publicPreview_icon ( $path, $token ) {
86
-	return(\publicPreview_icon( $path, $token ));
86
+    return(\publicPreview_icon( $path, $token ));
87 87
 }
88 88
 
89 89
 /**
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
  * @deprecated 8.0.0 Use \OCP\Template::human_file_size() instead
95 95
  */
96 96
 function human_file_size( $bytes ) {
97
-	return(\human_file_size( $bytes ));
97
+    return(\human_file_size( $bytes ));
98 98
 }
99 99
 
100 100
 
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
  * @deprecated 8.0.0 Use \OCP\Template::relative_modified_date() instead
108 108
  */
109 109
 function relative_modified_date( $timestamp, $dateOnly = false ) {
110
-	return(\relative_modified_date($timestamp, null, $dateOnly));
110
+    return(\relative_modified_date($timestamp, null, $dateOnly));
111 111
 }
112 112
 
113 113
 
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
  * @deprecated 8.0.0 Use \OCP\Template::human_file_size() instead
119 119
  */
120 120
 function simple_file_size($bytes) {
121
-	return(\human_file_size($bytes));
121
+    return(\human_file_size($bytes));
122 122
 }
123 123
 
124 124
 
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
  * @deprecated 8.0.0 Use \OCP\Template::html_select_options() instead
132 132
  */
133 133
 function html_select_options($options, $selected, $params=array()) {
134
-	return(\html_select_options($options, $selected, $params));
134
+    return(\html_select_options($options, $selected, $params));
135 135
 }
136 136
 
137 137
 
@@ -142,90 +142,90 @@  discard block
 block discarded – undo
142 142
  * @since 8.0.0
143 143
  */
144 144
 class Template extends \OC_Template {
145
-	/**
146
-	 * Make OC_Helper::imagePath available as a simple function
147
-	 *
148
-	 * @see \OCP\IURLGenerator::imagePath
149
-	 *
150
-	 * @param string $app
151
-	 * @param string $image
152
-	 * @return string to the image
153
-	 * @since 8.0.0
154
-	 */
155
-	public static function image_path($app, $image) {
156
-		return \image_path($app, $image);
157
-	}
158
-
159
-
160
-	/**
161
-	 * Make OC_Helper::mimetypeIcon available as a simple function
162
-	 *
163
-	 * @param string $mimetype
164
-	 * @return string to the image of this file type.
165
-	 * @since 8.0.0
166
-	 */
167
-	public static function mimetype_icon($mimetype) {
168
-		return \mimetype_icon($mimetype);
169
-	}
170
-
171
-	/**
172
-	 * Make preview_icon available as a simple function
173
-	 *
174
-	 * @param string $path path to file
175
-	 * @return string to the preview of the image
176
-	 * @since 8.0.0
177
-	 */
178
-	public static function preview_icon($path) {
179
-		return \preview_icon($path);
180
-	}
181
-
182
-	/**
183
-	 * Make publicpreview_icon available as a simple function
184
-	 * Returns the path to the preview of the image.
185
-	 *
186
-	 * @param string $path of file
187
-	 * @param string $token
188
-	 * @return string link to the preview
189
-	 * @since 8.0.0
190
-	 */
191
-	public static function publicPreview_icon($path, $token) {
192
-		return \publicPreview_icon($path, $token);
193
-	}
194
-
195
-	/**
196
-	 * Make OC_Helper::humanFileSize available as a simple function
197
-	 * Example: 2048 to 2 kB.
198
-	 *
199
-	 * @param int $bytes in bytes
200
-	 * @return string size as string
201
-	 * @since 8.0.0
202
-	 */
203
-	public static function human_file_size($bytes) {
204
-		return \human_file_size($bytes);
205
-	}
206
-
207
-	/**
208
-	 * Return the relative date in relation to today. Returns something like "last hour" or "two month ago"
209
-	 *
210
-	 * @param int $timestamp unix timestamp
211
-	 * @param boolean $dateOnly
212
-	 * @return string human readable interpretation of the timestamp
213
-	 * @since 8.0.0
214
-	 */
215
-	public static function relative_modified_date($timestamp, $dateOnly = false) {
216
-		return \relative_modified_date($timestamp, null, $dateOnly);
217
-	}
218
-
219
-	/**
220
-	 * Generate html code for an options block.
221
-	 *
222
-	 * @param array $options the options
223
-	 * @param mixed $selected which one is selected?
224
-	 * @param array $params the parameters
225
-	 * @return string html options
226
-	 * @since 8.0.0
227
-	 */
228
-	public static function html_select_options($options, $selected, $params=array()) {
229
-		return \html_select_options($options, $selected, $params);
230
-	}
145
+    /**
146
+     * Make OC_Helper::imagePath available as a simple function
147
+     *
148
+     * @see \OCP\IURLGenerator::imagePath
149
+     *
150
+     * @param string $app
151
+     * @param string $image
152
+     * @return string to the image
153
+     * @since 8.0.0
154
+     */
155
+    public static function image_path($app, $image) {
156
+        return \image_path($app, $image);
157
+    }
158
+
159
+
160
+    /**
161
+     * Make OC_Helper::mimetypeIcon available as a simple function
162
+     *
163
+     * @param string $mimetype
164
+     * @return string to the image of this file type.
165
+     * @since 8.0.0
166
+     */
167
+    public static function mimetype_icon($mimetype) {
168
+        return \mimetype_icon($mimetype);
169
+    }
170
+
171
+    /**
172
+     * Make preview_icon available as a simple function
173
+     *
174
+     * @param string $path path to file
175
+     * @return string to the preview of the image
176
+     * @since 8.0.0
177
+     */
178
+    public static function preview_icon($path) {
179
+        return \preview_icon($path);
180
+    }
181
+
182
+    /**
183
+     * Make publicpreview_icon available as a simple function
184
+     * Returns the path to the preview of the image.
185
+     *
186
+     * @param string $path of file
187
+     * @param string $token
188
+     * @return string link to the preview
189
+     * @since 8.0.0
190
+     */
191
+    public static function publicPreview_icon($path, $token) {
192
+        return \publicPreview_icon($path, $token);
193
+    }
194
+
195
+    /**
196
+     * Make OC_Helper::humanFileSize available as a simple function
197
+     * Example: 2048 to 2 kB.
198
+     *
199
+     * @param int $bytes in bytes
200
+     * @return string size as string
201
+     * @since 8.0.0
202
+     */
203
+    public static function human_file_size($bytes) {
204
+        return \human_file_size($bytes);
205
+    }
206
+
207
+    /**
208
+     * Return the relative date in relation to today. Returns something like "last hour" or "two month ago"
209
+     *
210
+     * @param int $timestamp unix timestamp
211
+     * @param boolean $dateOnly
212
+     * @return string human readable interpretation of the timestamp
213
+     * @since 8.0.0
214
+     */
215
+    public static function relative_modified_date($timestamp, $dateOnly = false) {
216
+        return \relative_modified_date($timestamp, null, $dateOnly);
217
+    }
218
+
219
+    /**
220
+     * Generate html code for an options block.
221
+     *
222
+     * @param array $options the options
223
+     * @param mixed $selected which one is selected?
224
+     * @param array $params the parameters
225
+     * @return string html options
226
+     * @since 8.0.0
227
+     */
228
+    public static function html_select_options($options, $selected, $params=array()) {
229
+        return \html_select_options($options, $selected, $params);
230
+    }
231 231
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
  * @see \OCP\IURLGenerator::imagePath
50 50
  * @deprecated 8.0.0 Use \OCP\Template::image_path() instead
51 51
  */
52
-function image_path( $app, $image ) {
53
-	return(\image_path( $app, $image ));
52
+function image_path($app, $image) {
53
+	return(\image_path($app, $image));
54 54
 }
55 55
 
56 56
 
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
  * @return string to the image of this file type.
61 61
  * @deprecated 8.0.0 Use \OCP\Template::mimetype_icon() instead
62 62
  */
63
-function mimetype_icon( $mimetype ) {
64
-	return(\mimetype_icon( $mimetype ));
63
+function mimetype_icon($mimetype) {
64
+	return(\mimetype_icon($mimetype));
65 65
 }
66 66
 
67 67
 /**
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
  * @return string to the preview of the image
71 71
  * @deprecated 8.0.0 Use \OCP\Template::preview_icon() instead
72 72
  */
73
-function preview_icon( $path ) {
74
-	return(\preview_icon( $path ));
73
+function preview_icon($path) {
74
+	return(\preview_icon($path));
75 75
 }
76 76
 
77 77
 /**
@@ -82,8 +82,8 @@  discard block
 block discarded – undo
82 82
  * @return string link to the preview
83 83
  * @deprecated 8.0.0 Use \OCP\Template::publicPreview_icon() instead
84 84
  */
85
-function publicPreview_icon ( $path, $token ) {
86
-	return(\publicPreview_icon( $path, $token ));
85
+function publicPreview_icon($path, $token) {
86
+	return(\publicPreview_icon($path, $token));
87 87
 }
88 88
 
89 89
 /**
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
  * @return string size as string
94 94
  * @deprecated 8.0.0 Use \OCP\Template::human_file_size() instead
95 95
  */
96
-function human_file_size( $bytes ) {
97
-	return(\human_file_size( $bytes ));
96
+function human_file_size($bytes) {
97
+	return(\human_file_size($bytes));
98 98
 }
99 99
 
100 100
 
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
  *
107 107
  * @deprecated 8.0.0 Use \OCP\Template::relative_modified_date() instead
108 108
  */
109
-function relative_modified_date( $timestamp, $dateOnly = false ) {
109
+function relative_modified_date($timestamp, $dateOnly = false) {
110 110
 	return(\relative_modified_date($timestamp, null, $dateOnly));
111 111
 }
112 112
 
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
  * @return string html options
131 131
  * @deprecated 8.0.0 Use \OCP\Template::html_select_options() instead
132 132
  */
133
-function html_select_options($options, $selected, $params=array()) {
133
+function html_select_options($options, $selected, $params = array()) {
134 134
 	return(\html_select_options($options, $selected, $params));
135 135
 }
136 136
 
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 	 * @return string html options
226 226
 	 * @since 8.0.0
227 227
 	 */
228
-	public static function html_select_options($options, $selected, $params=array()) {
228
+	public static function html_select_options($options, $selected, $params = array()) {
229 229
 		return \html_select_options($options, $selected, $params);
230 230
 	}
231 231
 }
Please login to merge, or discard this patch.
lib/public/Util.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -544,7 +544,7 @@
 block discarded – undo
544 544
 	 * @param array $input The array to work on
545 545
 	 * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default)
546 546
 	 * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
547
-	 * @return array
547
+	 * @return string
548 548
 	 * @since 4.5.0
549 549
 	 */
550 550
 	public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') {
Please login to merge, or discard this patch.
Indentation   +648 added lines, -648 removed lines patch added patch discarded remove patch
@@ -57,654 +57,654 @@
 block discarded – undo
57 57
  * @since 4.0.0
58 58
  */
59 59
 class Util {
60
-	// consts for Logging
61
-	const DEBUG=0;
62
-	const INFO=1;
63
-	const WARN=2;
64
-	const ERROR=3;
65
-	const FATAL=4;
66
-
67
-	/** \OCP\Share\IManager */
68
-	private static $shareManager;
69
-
70
-	/**
71
-	 * get the current installed version of ownCloud
72
-	 * @return array
73
-	 * @since 4.0.0
74
-	 */
75
-	public static function getVersion() {
76
-		return(\OC_Util::getVersion());
77
-	}
60
+    // consts for Logging
61
+    const DEBUG=0;
62
+    const INFO=1;
63
+    const WARN=2;
64
+    const ERROR=3;
65
+    const FATAL=4;
66
+
67
+    /** \OCP\Share\IManager */
68
+    private static $shareManager;
69
+
70
+    /**
71
+     * get the current installed version of ownCloud
72
+     * @return array
73
+     * @since 4.0.0
74
+     */
75
+    public static function getVersion() {
76
+        return(\OC_Util::getVersion());
77
+    }
78 78
 	
79
-	/**
80
-	 * Set current update channel
81
-	 * @param string $channel
82
-	 * @since 8.1.0
83
-	 */
84
-	public static function setChannel($channel) {
85
-		\OC::$server->getConfig()->setSystemValue('updater.release.channel', $channel);
86
-	}
79
+    /**
80
+     * Set current update channel
81
+     * @param string $channel
82
+     * @since 8.1.0
83
+     */
84
+    public static function setChannel($channel) {
85
+        \OC::$server->getConfig()->setSystemValue('updater.release.channel', $channel);
86
+    }
87 87
 	
88
-	/**
89
-	 * Get current update channel
90
-	 * @return string
91
-	 * @since 8.1.0
92
-	 */
93
-	public static function getChannel() {
94
-		return \OC_Util::getChannel();
95
-	}
96
-
97
-	/**
98
-	 * send an email
99
-	 * @param string $toaddress
100
-	 * @param string $toname
101
-	 * @param string $subject
102
-	 * @param string $mailtext
103
-	 * @param string $fromaddress
104
-	 * @param string $fromname
105
-	 * @param int $html
106
-	 * @param string $altbody
107
-	 * @param string $ccaddress
108
-	 * @param string $ccname
109
-	 * @param string $bcc
110
-	 * @deprecated 8.1.0 Use \OCP\Mail\IMailer instead
111
-	 * @since 4.0.0
112
-	 */
113
-	public static function sendMail($toaddress, $toname, $subject, $mailtext, $fromaddress, $fromname,
114
-		$html = 0, $altbody = '', $ccaddress = '', $ccname = '', $bcc = '') {
115
-		$mailer = \OC::$server->getMailer();
116
-		$message = $mailer->createMessage();
117
-		$message->setTo([$toaddress => $toname]);
118
-		$message->setSubject($subject);
119
-		$message->setPlainBody($mailtext);
120
-		$message->setFrom([$fromaddress => $fromname]);
121
-		if($html === 1) {
122
-			$message->setHTMLBody($altbody);
123
-		}
124
-
125
-		if($altbody === '') {
126
-			$message->setHTMLBody($mailtext);
127
-			$message->setPlainBody('');
128
-		} else {
129
-			$message->setHtmlBody($mailtext);
130
-			$message->setPlainBody($altbody);
131
-		}
132
-
133
-		if(!empty($ccaddress)) {
134
-			if(!empty($ccname)) {
135
-				$message->setCc([$ccaddress => $ccname]);
136
-			} else {
137
-				$message->setCc([$ccaddress]);
138
-			}
139
-		}
140
-		if(!empty($bcc)) {
141
-			$message->setBcc([$bcc]);
142
-		}
143
-
144
-		$mailer->send($message);
145
-	}
146
-
147
-	/**
148
-	 * write a message in the log
149
-	 * @param string $app
150
-	 * @param string $message
151
-	 * @param int $level
152
-	 * @since 4.0.0
153
-	 */
154
-	public static function writeLog( $app, $message, $level ) {
155
-		$context = ['app' => $app];
156
-		\OC::$server->getLogger()->log($level, $message, $context);
157
-	}
158
-
159
-	/**
160
-	 * write exception into the log
161
-	 * @param string $app app name
162
-	 * @param \Exception $ex exception to log
163
-	 * @param int $level log level, defaults to \OCP\Util::FATAL
164
-	 * @since ....0.0 - parameter $level was added in 7.0.0
165
-	 * @deprecated 8.2.0 use logException of \OCP\ILogger
166
-	 */
167
-	public static function logException( $app, \Exception $ex, $level = \OCP\Util::FATAL ) {
168
-		\OC::$server->getLogger()->logException($ex, ['app' => $app]);
169
-	}
170
-
171
-	/**
172
-	 * check if sharing is disabled for the current user
173
-	 *
174
-	 * @return boolean
175
-	 * @since 7.0.0
176
-	 * @deprecated 9.1.0 Use \OC::$server->getShareManager()->sharingDisabledForUser
177
-	 */
178
-	public static function isSharingDisabledForUser() {
179
-		if (self::$shareManager === null) {
180
-			self::$shareManager = \OC::$server->getShareManager();
181
-		}
182
-
183
-		$user = \OC::$server->getUserSession()->getUser();
184
-		if ($user !== null) {
185
-			$user = $user->getUID();
186
-		}
187
-
188
-		return self::$shareManager->sharingDisabledForUser($user);
189
-	}
190
-
191
-	/**
192
-	 * get l10n object
193
-	 * @param string $application
194
-	 * @param string|null $language
195
-	 * @return \OCP\IL10N
196
-	 * @since 6.0.0 - parameter $language was added in 8.0.0
197
-	 */
198
-	public static function getL10N($application, $language = null) {
199
-		return \OC::$server->getL10N($application, $language);
200
-	}
201
-
202
-	/**
203
-	 * add a css file
204
-	 * @param string $application
205
-	 * @param string $file
206
-	 * @since 4.0.0
207
-	 */
208
-	public static function addStyle( $application, $file = null ) {
209
-		\OC_Util::addStyle( $application, $file );
210
-	}
211
-
212
-	/**
213
-	 * add a javascript file
214
-	 * @param string $application
215
-	 * @param string $file
216
-	 * @since 4.0.0
217
-	 */
218
-	public static function addScript( $application, $file = null ) {
219
-		\OC_Util::addScript( $application, $file );
220
-	}
221
-
222
-	/**
223
-	 * Add a translation JS file
224
-	 * @param string $application application id
225
-	 * @param string $languageCode language code, defaults to the current locale
226
-	 * @since 8.0.0
227
-	 */
228
-	public static function addTranslations($application, $languageCode = null) {
229
-		\OC_Util::addTranslations($application, $languageCode);
230
-	}
231
-
232
-	/**
233
-	 * Add a custom element to the header
234
-	 * If $text is null then the element will be written as empty element.
235
-	 * So use "" to get a closing tag.
236
-	 * @param string $tag tag name of the element
237
-	 * @param array $attributes array of attributes for the element
238
-	 * @param string $text the text content for the element
239
-	 * @since 4.0.0
240
-	 */
241
-	public static function addHeader($tag, $attributes, $text=null) {
242
-		\OC_Util::addHeader($tag, $attributes, $text);
243
-	}
244
-
245
-	/**
246
-	 * formats a timestamp in the "right" way
247
-	 * @param int $timestamp $timestamp
248
-	 * @param bool $dateOnly option to omit time from the result
249
-	 * @param DateTimeZone|string $timeZone where the given timestamp shall be converted to
250
-	 * @return string timestamp
251
-	 *
252
-	 * @deprecated 8.0.0 Use \OC::$server->query('DateTimeFormatter') instead
253
-	 * @since 4.0.0
254
-	 */
255
-	public static function formatDate($timestamp, $dateOnly=false, $timeZone = null) {
256
-		return(\OC_Util::formatDate($timestamp, $dateOnly, $timeZone));
257
-	}
258
-
259
-	/**
260
-	 * check if some encrypted files are stored
261
-	 * @return bool
262
-	 *
263
-	 * @deprecated 8.1.0 No longer required
264
-	 * @since 6.0.0
265
-	 */
266
-	public static function encryptedFiles() {
267
-		return false;
268
-	}
269
-
270
-	/**
271
-	 * Creates an absolute url to the given app and file.
272
-	 * @param string $app app
273
-	 * @param string $file file
274
-	 * @param array $args array with param=>value, will be appended to the returned url
275
-	 * 	The value of $args will be urlencoded
276
-	 * @return string the url
277
-	 * @since 4.0.0 - parameter $args was added in 4.5.0
278
-	 */
279
-	public static function linkToAbsolute( $app, $file, $args = array() ) {
280
-		$urlGenerator = \OC::$server->getURLGenerator();
281
-		return $urlGenerator->getAbsoluteURL(
282
-			$urlGenerator->linkTo($app, $file, $args)
283
-		);
284
-	}
285
-
286
-	/**
287
-	 * Creates an absolute url for remote use.
288
-	 * @param string $service id
289
-	 * @return string the url
290
-	 * @since 4.0.0
291
-	 */
292
-	public static function linkToRemote( $service ) {
293
-		$urlGenerator = \OC::$server->getURLGenerator();
294
-		$remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service;
295
-		return $urlGenerator->getAbsoluteURL(
296
-			$remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '')
297
-		);
298
-	}
299
-
300
-	/**
301
-	 * Creates an absolute url for public use
302
-	 * @param string $service id
303
-	 * @return string the url
304
-	 * @since 4.5.0
305
-	 */
306
-	public static function linkToPublic($service) {
307
-		return \OC_Helper::linkToPublic($service);
308
-	}
309
-
310
-	/**
311
-	 * Creates an url using a defined route
312
-	 * @param string $route
313
-	 * @param array $parameters
314
-	 * @internal param array $args with param=>value, will be appended to the returned url
315
-	 * @return string the url
316
-	 * @deprecated 8.1.0 Use \OC::$server->getURLGenerator()->linkToRoute($route, $parameters)
317
-	 * @since 5.0.0
318
-	 */
319
-	public static function linkToRoute( $route, $parameters = array() ) {
320
-		return \OC::$server->getURLGenerator()->linkToRoute($route, $parameters);
321
-	}
322
-
323
-	/**
324
-	 * Creates an url to the given app and file
325
-	 * @param string $app app
326
-	 * @param string $file file
327
-	 * @param array $args array with param=>value, will be appended to the returned url
328
-	 * 	The value of $args will be urlencoded
329
-	 * @return string the url
330
-	 * @deprecated 8.1.0 Use \OC::$server->getURLGenerator()->linkTo($app, $file, $args)
331
-	 * @since 4.0.0 - parameter $args was added in 4.5.0
332
-	 */
333
-	public static function linkTo( $app, $file, $args = array() ) {
334
-		return \OC::$server->getURLGenerator()->linkTo($app, $file, $args);
335
-	}
336
-
337
-	/**
338
-	 * Returns the server host, even if the website uses one or more reverse proxy
339
-	 * @return string the server host
340
-	 * @deprecated 8.1.0 Use \OCP\IRequest::getServerHost
341
-	 * @since 4.0.0
342
-	 */
343
-	public static function getServerHost() {
344
-		return \OC::$server->getRequest()->getServerHost();
345
-	}
346
-
347
-	/**
348
-	 * Returns the server host name without an eventual port number
349
-	 * @return string the server hostname
350
-	 * @since 5.0.0
351
-	 */
352
-	public static function getServerHostName() {
353
-		$host_name = self::getServerHost();
354
-		// strip away port number (if existing)
355
-		$colon_pos = strpos($host_name, ':');
356
-		if ($colon_pos != FALSE) {
357
-			$host_name = substr($host_name, 0, $colon_pos);
358
-		}
359
-		return $host_name;
360
-	}
361
-
362
-	/**
363
-	 * Returns the default email address
364
-	 * @param string $user_part the user part of the address
365
-	 * @return string the default email address
366
-	 *
367
-	 * Assembles a default email address (using the server hostname
368
-	 * and the given user part, and returns it
369
-	 * Example: when given lostpassword-noreply as $user_part param,
370
-	 *     and is currently accessed via http(s)://example.com/,
371
-	 *     it would return '[email protected]'
372
-	 *
373
-	 * If the configuration value 'mail_from_address' is set in
374
-	 * config.php, this value will override the $user_part that
375
-	 * is passed to this function
376
-	 * @since 5.0.0
377
-	 */
378
-	public static function getDefaultEmailAddress($user_part) {
379
-		$config = \OC::$server->getConfig();
380
-		$user_part = $config->getSystemValue('mail_from_address', $user_part);
381
-		$host_name = self::getServerHostName();
382
-		$host_name = $config->getSystemValue('mail_domain', $host_name);
383
-		$defaultEmailAddress = $user_part.'@'.$host_name;
384
-
385
-		$mailer = \OC::$server->getMailer();
386
-		if ($mailer->validateMailAddress($defaultEmailAddress)) {
387
-			return $defaultEmailAddress;
388
-		}
389
-
390
-		// in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain'
391
-		return $user_part.'@localhost.localdomain';
392
-	}
393
-
394
-	/**
395
-	 * Returns the server protocol. It respects reverse proxy servers and load balancers
396
-	 * @return string the server protocol
397
-	 * @deprecated 8.1.0 Use \OCP\IRequest::getServerProtocol
398
-	 * @since 4.5.0
399
-	 */
400
-	public static function getServerProtocol() {
401
-		return \OC::$server->getRequest()->getServerProtocol();
402
-	}
403
-
404
-	/**
405
-	 * Returns the request uri, even if the website uses one or more reverse proxies
406
-	 * @return string the request uri
407
-	 * @deprecated 8.1.0 Use \OCP\IRequest::getRequestUri
408
-	 * @since 5.0.0
409
-	 */
410
-	public static function getRequestUri() {
411
-		return \OC::$server->getRequest()->getRequestUri();
412
-	}
413
-
414
-	/**
415
-	 * Returns the script name, even if the website uses one or more reverse proxies
416
-	 * @return string the script name
417
-	 * @deprecated 8.1.0 Use \OCP\IRequest::getScriptName
418
-	 * @since 5.0.0
419
-	 */
420
-	public static function getScriptName() {
421
-		return \OC::$server->getRequest()->getScriptName();
422
-	}
423
-
424
-	/**
425
-	 * Creates path to an image
426
-	 * @param string $app app
427
-	 * @param string $image image name
428
-	 * @return string the url
429
-	 * @deprecated 8.1.0 Use \OC::$server->getURLGenerator()->imagePath($app, $image)
430
-	 * @since 4.0.0
431
-	 */
432
-	public static function imagePath( $app, $image ) {
433
-		return \OC::$server->getURLGenerator()->imagePath($app, $image);
434
-	}
435
-
436
-	/**
437
-	 * Make a human file size (2048 to 2 kB)
438
-	 * @param int $bytes file size in bytes
439
-	 * @return string a human readable file size
440
-	 * @since 4.0.0
441
-	 */
442
-	public static function humanFileSize( $bytes ) {
443
-		return(\OC_Helper::humanFileSize( $bytes ));
444
-	}
445
-
446
-	/**
447
-	 * Make a computer file size (2 kB to 2048)
448
-	 * @param string $str file size in a fancy format
449
-	 * @return int a file size in bytes
450
-	 *
451
-	 * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418
452
-	 * @since 4.0.0
453
-	 */
454
-	public static function computerFileSize( $str ) {
455
-		return(\OC_Helper::computerFileSize( $str ));
456
-	}
457
-
458
-	/**
459
-	 * connects a function to a hook
460
-	 *
461
-	 * @param string $signalClass class name of emitter
462
-	 * @param string $signalName name of signal
463
-	 * @param string|object $slotClass class name of slot
464
-	 * @param string $slotName name of slot
465
-	 * @return bool
466
-	 *
467
-	 * This function makes it very easy to connect to use hooks.
468
-	 *
469
-	 * TODO: write example
470
-	 * @since 4.0.0
471
-	 */
472
-	static public function connectHook($signalClass, $signalName, $slotClass, $slotName ) {
473
-		return(\OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName ));
474
-	}
475
-
476
-	/**
477
-	 * Emits a signal. To get data from the slot use references!
478
-	 * @param string $signalclass class name of emitter
479
-	 * @param string $signalname name of signal
480
-	 * @param array $params default: array() array with additional data
481
-	 * @return bool true if slots exists or false if not
482
-	 *
483
-	 * TODO: write example
484
-	 * @since 4.0.0
485
-	 */
486
-	static public function emitHook( $signalclass, $signalname, $params = array()) {
487
-		return(\OC_Hook::emit( $signalclass, $signalname, $params ));
488
-	}
489
-
490
-	/**
491
-	 * Cached encrypted CSRF token. Some static unit-tests of ownCloud compare
492
-	 * multiple OC_Template elements which invoke `callRegister`. If the value
493
-	 * would not be cached these unit-tests would fail.
494
-	 * @var string
495
-	 */
496
-	private static $token = '';
497
-
498
-	/**
499
-	 * Register an get/post call. This is important to prevent CSRF attacks
500
-	 * @since 4.5.0
501
-	 */
502
-	public static function callRegister() {
503
-		if(self::$token === '') {
504
-			self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue();
505
-		}
506
-		return self::$token;
507
-	}
508
-
509
-	/**
510
-	 * Check an ajax get/post call if the request token is valid. exit if not.
511
-	 * @since 4.5.0
512
-	 * @deprecated 9.0.0 Use annotations based on the app framework.
513
-	 */
514
-	public static function callCheck() {
515
-		if(!\OC::$server->getRequest()->passesStrictCookieCheck()) {
516
-			header('Location: '.\OC::$WEBROOT);
517
-			exit();
518
-		}
519
-
520
-		if (!(\OC::$server->getRequest()->passesCSRFCheck())) {
521
-			exit();
522
-		}
523
-	}
524
-
525
-	/**
526
-	 * Used to sanitize HTML
527
-	 *
528
-	 * This function is used to sanitize HTML and should be applied on any
529
-	 * string or array of strings before displaying it on a web page.
530
-	 *
531
-	 * @param string|array $value
532
-	 * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter.
533
-	 * @since 4.5.0
534
-	 */
535
-	public static function sanitizeHTML($value) {
536
-		return \OC_Util::sanitizeHTML($value);
537
-	}
538
-
539
-	/**
540
-	 * Public function to encode url parameters
541
-	 *
542
-	 * This function is used to encode path to file before output.
543
-	 * Encoding is done according to RFC 3986 with one exception:
544
-	 * Character '/' is preserved as is.
545
-	 *
546
-	 * @param string $component part of URI to encode
547
-	 * @return string
548
-	 * @since 6.0.0
549
-	 */
550
-	public static function encodePath($component) {
551
-		return(\OC_Util::encodePath($component));
552
-	}
553
-
554
-	/**
555
-	 * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.
556
-	 *
557
-	 * @param array $input The array to work on
558
-	 * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default)
559
-	 * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
560
-	 * @return array
561
-	 * @since 4.5.0
562
-	 */
563
-	public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') {
564
-		return(\OC_Helper::mb_array_change_key_case($input, $case, $encoding));
565
-	}
566
-
567
-	/**
568
-	 * replaces a copy of string delimited by the start and (optionally) length parameters with the string given in replacement.
569
-	 *
570
-	 * @param string $string The input string. Opposite to the PHP build-in function does not accept an array.
571
-	 * @param string $replacement The replacement string.
572
-	 * @param int $start If start is positive, the replacing will begin at the start'th offset into string. If start is negative, the replacing will begin at the start'th character from the end of string.
573
-	 * @param int $length Length of the part to be replaced
574
-	 * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
575
-	 * @return string
576
-	 * @since 4.5.0
577
-	 * @deprecated 8.2.0 Use substr_replace() instead.
578
-	 */
579
-	public static function mb_substr_replace($string, $replacement, $start, $length = null, $encoding = 'UTF-8') {
580
-		return substr_replace($string, $replacement, $start, $length);
581
-	}
582
-
583
-	/**
584
-	 * Replace all occurrences of the search string with the replacement string
585
-	 *
586
-	 * @param string $search The value being searched for, otherwise known as the needle. String.
587
-	 * @param string $replace The replacement string.
588
-	 * @param string $subject The string or array being searched and replaced on, otherwise known as the haystack.
589
-	 * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
590
-	 * @param int $count If passed, this will be set to the number of replacements performed.
591
-	 * @return string
592
-	 * @since 4.5.0
593
-	 * @deprecated 8.2.0 Use str_replace() instead.
594
-	 */
595
-	public static function mb_str_replace($search, $replace, $subject, $encoding = 'UTF-8', &$count = null) {
596
-		return str_replace($search, $replace, $subject, $count);
597
-	}
598
-
599
-	/**
600
-	 * performs a search in a nested array
601
-	 *
602
-	 * @param array $haystack the array to be searched
603
-	 * @param string $needle the search string
604
-	 * @param int $index optional, only search this key name
605
-	 * @return mixed the key of the matching field, otherwise false
606
-	 * @since 4.5.0
607
-	 */
608
-	public static function recursiveArraySearch($haystack, $needle, $index = null) {
609
-		return(\OC_Helper::recursiveArraySearch($haystack, $needle, $index));
610
-	}
611
-
612
-	/**
613
-	 * calculates the maximum upload size respecting system settings, free space and user quota
614
-	 *
615
-	 * @param string $dir the current folder where the user currently operates
616
-	 * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly
617
-	 * @return int number of bytes representing
618
-	 * @since 5.0.0
619
-	 */
620
-	public static function maxUploadFilesize($dir, $free = null) {
621
-		return \OC_Helper::maxUploadFilesize($dir, $free);
622
-	}
623
-
624
-	/**
625
-	 * Calculate free space left within user quota
626
-	 * @param string $dir the current folder where the user currently operates
627
-	 * @return int number of bytes representing
628
-	 * @since 7.0.0
629
-	 */
630
-	public static function freeSpace($dir) {
631
-		return \OC_Helper::freeSpace($dir);
632
-	}
633
-
634
-	/**
635
-	 * Calculate PHP upload limit
636
-	 *
637
-	 * @return int number of bytes representing
638
-	 * @since 7.0.0
639
-	 */
640
-	public static function uploadLimit() {
641
-		return \OC_Helper::uploadLimit();
642
-	}
643
-
644
-	/**
645
-	 * Returns whether the given file name is valid
646
-	 * @param string $file file name to check
647
-	 * @return bool true if the file name is valid, false otherwise
648
-	 * @deprecated 8.1.0 use \OC\Files\View::verifyPath()
649
-	 * @since 7.0.0
650
-	 */
651
-	public static function isValidFileName($file) {
652
-		return \OC_Util::isValidFileName($file);
653
-	}
654
-
655
-	/**
656
-	 * Generates a cryptographic secure pseudo-random string
657
-	 * @param int $length of the random string
658
-	 * @return string
659
-	 * @deprecated 8.0.0 Use \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate($length); instead
660
-	 * @since 7.0.0
661
-	 */
662
-	public static function generateRandomBytes($length = 30) {
663
-		return \OC::$server->getSecureRandom()->generate($length, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS);
664
-	}
665
-
666
-	/**
667
-	 * Compare two strings to provide a natural sort
668
-	 * @param string $a first string to compare
669
-	 * @param string $b second string to compare
670
-	 * @return -1 if $b comes before $a, 1 if $a comes before $b
671
-	 * or 0 if the strings are identical
672
-	 * @since 7.0.0
673
-	 */
674
-	public static function naturalSortCompare($a, $b) {
675
-		return \OC\NaturalSort::getInstance()->compare($a, $b);
676
-	}
677
-
678
-	/**
679
-	 * check if a password is required for each public link
680
-	 * @return boolean
681
-	 * @since 7.0.0
682
-	 */
683
-	public static function isPublicLinkPasswordRequired() {
684
-		return \OC_Util::isPublicLinkPasswordRequired();
685
-	}
686
-
687
-	/**
688
-	 * check if share API enforces a default expire date
689
-	 * @return boolean
690
-	 * @since 8.0.0
691
-	 */
692
-	public static function isDefaultExpireDateEnforced() {
693
-		return \OC_Util::isDefaultExpireDateEnforced();
694
-	}
695
-
696
-	protected static $needUpgradeCache = null;
697
-
698
-	/**
699
-	 * Checks whether the current version needs upgrade.
700
-	 *
701
-	 * @return bool true if upgrade is needed, false otherwise
702
-	 * @since 7.0.0
703
-	 */
704
-	public static function needUpgrade() {
705
-		if (!isset(self::$needUpgradeCache)) {
706
-			self::$needUpgradeCache=\OC_Util::needUpgrade(\OC::$server->getSystemConfig());
707
-		}		
708
-		return self::$needUpgradeCache;
709
-	}
88
+    /**
89
+     * Get current update channel
90
+     * @return string
91
+     * @since 8.1.0
92
+     */
93
+    public static function getChannel() {
94
+        return \OC_Util::getChannel();
95
+    }
96
+
97
+    /**
98
+     * send an email
99
+     * @param string $toaddress
100
+     * @param string $toname
101
+     * @param string $subject
102
+     * @param string $mailtext
103
+     * @param string $fromaddress
104
+     * @param string $fromname
105
+     * @param int $html
106
+     * @param string $altbody
107
+     * @param string $ccaddress
108
+     * @param string $ccname
109
+     * @param string $bcc
110
+     * @deprecated 8.1.0 Use \OCP\Mail\IMailer instead
111
+     * @since 4.0.0
112
+     */
113
+    public static function sendMail($toaddress, $toname, $subject, $mailtext, $fromaddress, $fromname,
114
+        $html = 0, $altbody = '', $ccaddress = '', $ccname = '', $bcc = '') {
115
+        $mailer = \OC::$server->getMailer();
116
+        $message = $mailer->createMessage();
117
+        $message->setTo([$toaddress => $toname]);
118
+        $message->setSubject($subject);
119
+        $message->setPlainBody($mailtext);
120
+        $message->setFrom([$fromaddress => $fromname]);
121
+        if($html === 1) {
122
+            $message->setHTMLBody($altbody);
123
+        }
124
+
125
+        if($altbody === '') {
126
+            $message->setHTMLBody($mailtext);
127
+            $message->setPlainBody('');
128
+        } else {
129
+            $message->setHtmlBody($mailtext);
130
+            $message->setPlainBody($altbody);
131
+        }
132
+
133
+        if(!empty($ccaddress)) {
134
+            if(!empty($ccname)) {
135
+                $message->setCc([$ccaddress => $ccname]);
136
+            } else {
137
+                $message->setCc([$ccaddress]);
138
+            }
139
+        }
140
+        if(!empty($bcc)) {
141
+            $message->setBcc([$bcc]);
142
+        }
143
+
144
+        $mailer->send($message);
145
+    }
146
+
147
+    /**
148
+     * write a message in the log
149
+     * @param string $app
150
+     * @param string $message
151
+     * @param int $level
152
+     * @since 4.0.0
153
+     */
154
+    public static function writeLog( $app, $message, $level ) {
155
+        $context = ['app' => $app];
156
+        \OC::$server->getLogger()->log($level, $message, $context);
157
+    }
158
+
159
+    /**
160
+     * write exception into the log
161
+     * @param string $app app name
162
+     * @param \Exception $ex exception to log
163
+     * @param int $level log level, defaults to \OCP\Util::FATAL
164
+     * @since ....0.0 - parameter $level was added in 7.0.0
165
+     * @deprecated 8.2.0 use logException of \OCP\ILogger
166
+     */
167
+    public static function logException( $app, \Exception $ex, $level = \OCP\Util::FATAL ) {
168
+        \OC::$server->getLogger()->logException($ex, ['app' => $app]);
169
+    }
170
+
171
+    /**
172
+     * check if sharing is disabled for the current user
173
+     *
174
+     * @return boolean
175
+     * @since 7.0.0
176
+     * @deprecated 9.1.0 Use \OC::$server->getShareManager()->sharingDisabledForUser
177
+     */
178
+    public static function isSharingDisabledForUser() {
179
+        if (self::$shareManager === null) {
180
+            self::$shareManager = \OC::$server->getShareManager();
181
+        }
182
+
183
+        $user = \OC::$server->getUserSession()->getUser();
184
+        if ($user !== null) {
185
+            $user = $user->getUID();
186
+        }
187
+
188
+        return self::$shareManager->sharingDisabledForUser($user);
189
+    }
190
+
191
+    /**
192
+     * get l10n object
193
+     * @param string $application
194
+     * @param string|null $language
195
+     * @return \OCP\IL10N
196
+     * @since 6.0.0 - parameter $language was added in 8.0.0
197
+     */
198
+    public static function getL10N($application, $language = null) {
199
+        return \OC::$server->getL10N($application, $language);
200
+    }
201
+
202
+    /**
203
+     * add a css file
204
+     * @param string $application
205
+     * @param string $file
206
+     * @since 4.0.0
207
+     */
208
+    public static function addStyle( $application, $file = null ) {
209
+        \OC_Util::addStyle( $application, $file );
210
+    }
211
+
212
+    /**
213
+     * add a javascript file
214
+     * @param string $application
215
+     * @param string $file
216
+     * @since 4.0.0
217
+     */
218
+    public static function addScript( $application, $file = null ) {
219
+        \OC_Util::addScript( $application, $file );
220
+    }
221
+
222
+    /**
223
+     * Add a translation JS file
224
+     * @param string $application application id
225
+     * @param string $languageCode language code, defaults to the current locale
226
+     * @since 8.0.0
227
+     */
228
+    public static function addTranslations($application, $languageCode = null) {
229
+        \OC_Util::addTranslations($application, $languageCode);
230
+    }
231
+
232
+    /**
233
+     * Add a custom element to the header
234
+     * If $text is null then the element will be written as empty element.
235
+     * So use "" to get a closing tag.
236
+     * @param string $tag tag name of the element
237
+     * @param array $attributes array of attributes for the element
238
+     * @param string $text the text content for the element
239
+     * @since 4.0.0
240
+     */
241
+    public static function addHeader($tag, $attributes, $text=null) {
242
+        \OC_Util::addHeader($tag, $attributes, $text);
243
+    }
244
+
245
+    /**
246
+     * formats a timestamp in the "right" way
247
+     * @param int $timestamp $timestamp
248
+     * @param bool $dateOnly option to omit time from the result
249
+     * @param DateTimeZone|string $timeZone where the given timestamp shall be converted to
250
+     * @return string timestamp
251
+     *
252
+     * @deprecated 8.0.0 Use \OC::$server->query('DateTimeFormatter') instead
253
+     * @since 4.0.0
254
+     */
255
+    public static function formatDate($timestamp, $dateOnly=false, $timeZone = null) {
256
+        return(\OC_Util::formatDate($timestamp, $dateOnly, $timeZone));
257
+    }
258
+
259
+    /**
260
+     * check if some encrypted files are stored
261
+     * @return bool
262
+     *
263
+     * @deprecated 8.1.0 No longer required
264
+     * @since 6.0.0
265
+     */
266
+    public static function encryptedFiles() {
267
+        return false;
268
+    }
269
+
270
+    /**
271
+     * Creates an absolute url to the given app and file.
272
+     * @param string $app app
273
+     * @param string $file file
274
+     * @param array $args array with param=>value, will be appended to the returned url
275
+     * 	The value of $args will be urlencoded
276
+     * @return string the url
277
+     * @since 4.0.0 - parameter $args was added in 4.5.0
278
+     */
279
+    public static function linkToAbsolute( $app, $file, $args = array() ) {
280
+        $urlGenerator = \OC::$server->getURLGenerator();
281
+        return $urlGenerator->getAbsoluteURL(
282
+            $urlGenerator->linkTo($app, $file, $args)
283
+        );
284
+    }
285
+
286
+    /**
287
+     * Creates an absolute url for remote use.
288
+     * @param string $service id
289
+     * @return string the url
290
+     * @since 4.0.0
291
+     */
292
+    public static function linkToRemote( $service ) {
293
+        $urlGenerator = \OC::$server->getURLGenerator();
294
+        $remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service;
295
+        return $urlGenerator->getAbsoluteURL(
296
+            $remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '')
297
+        );
298
+    }
299
+
300
+    /**
301
+     * Creates an absolute url for public use
302
+     * @param string $service id
303
+     * @return string the url
304
+     * @since 4.5.0
305
+     */
306
+    public static function linkToPublic($service) {
307
+        return \OC_Helper::linkToPublic($service);
308
+    }
309
+
310
+    /**
311
+     * Creates an url using a defined route
312
+     * @param string $route
313
+     * @param array $parameters
314
+     * @internal param array $args with param=>value, will be appended to the returned url
315
+     * @return string the url
316
+     * @deprecated 8.1.0 Use \OC::$server->getURLGenerator()->linkToRoute($route, $parameters)
317
+     * @since 5.0.0
318
+     */
319
+    public static function linkToRoute( $route, $parameters = array() ) {
320
+        return \OC::$server->getURLGenerator()->linkToRoute($route, $parameters);
321
+    }
322
+
323
+    /**
324
+     * Creates an url to the given app and file
325
+     * @param string $app app
326
+     * @param string $file file
327
+     * @param array $args array with param=>value, will be appended to the returned url
328
+     * 	The value of $args will be urlencoded
329
+     * @return string the url
330
+     * @deprecated 8.1.0 Use \OC::$server->getURLGenerator()->linkTo($app, $file, $args)
331
+     * @since 4.0.0 - parameter $args was added in 4.5.0
332
+     */
333
+    public static function linkTo( $app, $file, $args = array() ) {
334
+        return \OC::$server->getURLGenerator()->linkTo($app, $file, $args);
335
+    }
336
+
337
+    /**
338
+     * Returns the server host, even if the website uses one or more reverse proxy
339
+     * @return string the server host
340
+     * @deprecated 8.1.0 Use \OCP\IRequest::getServerHost
341
+     * @since 4.0.0
342
+     */
343
+    public static function getServerHost() {
344
+        return \OC::$server->getRequest()->getServerHost();
345
+    }
346
+
347
+    /**
348
+     * Returns the server host name without an eventual port number
349
+     * @return string the server hostname
350
+     * @since 5.0.0
351
+     */
352
+    public static function getServerHostName() {
353
+        $host_name = self::getServerHost();
354
+        // strip away port number (if existing)
355
+        $colon_pos = strpos($host_name, ':');
356
+        if ($colon_pos != FALSE) {
357
+            $host_name = substr($host_name, 0, $colon_pos);
358
+        }
359
+        return $host_name;
360
+    }
361
+
362
+    /**
363
+     * Returns the default email address
364
+     * @param string $user_part the user part of the address
365
+     * @return string the default email address
366
+     *
367
+     * Assembles a default email address (using the server hostname
368
+     * and the given user part, and returns it
369
+     * Example: when given lostpassword-noreply as $user_part param,
370
+     *     and is currently accessed via http(s)://example.com/,
371
+     *     it would return '[email protected]'
372
+     *
373
+     * If the configuration value 'mail_from_address' is set in
374
+     * config.php, this value will override the $user_part that
375
+     * is passed to this function
376
+     * @since 5.0.0
377
+     */
378
+    public static function getDefaultEmailAddress($user_part) {
379
+        $config = \OC::$server->getConfig();
380
+        $user_part = $config->getSystemValue('mail_from_address', $user_part);
381
+        $host_name = self::getServerHostName();
382
+        $host_name = $config->getSystemValue('mail_domain', $host_name);
383
+        $defaultEmailAddress = $user_part.'@'.$host_name;
384
+
385
+        $mailer = \OC::$server->getMailer();
386
+        if ($mailer->validateMailAddress($defaultEmailAddress)) {
387
+            return $defaultEmailAddress;
388
+        }
389
+
390
+        // in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain'
391
+        return $user_part.'@localhost.localdomain';
392
+    }
393
+
394
+    /**
395
+     * Returns the server protocol. It respects reverse proxy servers and load balancers
396
+     * @return string the server protocol
397
+     * @deprecated 8.1.0 Use \OCP\IRequest::getServerProtocol
398
+     * @since 4.5.0
399
+     */
400
+    public static function getServerProtocol() {
401
+        return \OC::$server->getRequest()->getServerProtocol();
402
+    }
403
+
404
+    /**
405
+     * Returns the request uri, even if the website uses one or more reverse proxies
406
+     * @return string the request uri
407
+     * @deprecated 8.1.0 Use \OCP\IRequest::getRequestUri
408
+     * @since 5.0.0
409
+     */
410
+    public static function getRequestUri() {
411
+        return \OC::$server->getRequest()->getRequestUri();
412
+    }
413
+
414
+    /**
415
+     * Returns the script name, even if the website uses one or more reverse proxies
416
+     * @return string the script name
417
+     * @deprecated 8.1.0 Use \OCP\IRequest::getScriptName
418
+     * @since 5.0.0
419
+     */
420
+    public static function getScriptName() {
421
+        return \OC::$server->getRequest()->getScriptName();
422
+    }
423
+
424
+    /**
425
+     * Creates path to an image
426
+     * @param string $app app
427
+     * @param string $image image name
428
+     * @return string the url
429
+     * @deprecated 8.1.0 Use \OC::$server->getURLGenerator()->imagePath($app, $image)
430
+     * @since 4.0.0
431
+     */
432
+    public static function imagePath( $app, $image ) {
433
+        return \OC::$server->getURLGenerator()->imagePath($app, $image);
434
+    }
435
+
436
+    /**
437
+     * Make a human file size (2048 to 2 kB)
438
+     * @param int $bytes file size in bytes
439
+     * @return string a human readable file size
440
+     * @since 4.0.0
441
+     */
442
+    public static function humanFileSize( $bytes ) {
443
+        return(\OC_Helper::humanFileSize( $bytes ));
444
+    }
445
+
446
+    /**
447
+     * Make a computer file size (2 kB to 2048)
448
+     * @param string $str file size in a fancy format
449
+     * @return int a file size in bytes
450
+     *
451
+     * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418
452
+     * @since 4.0.0
453
+     */
454
+    public static function computerFileSize( $str ) {
455
+        return(\OC_Helper::computerFileSize( $str ));
456
+    }
457
+
458
+    /**
459
+     * connects a function to a hook
460
+     *
461
+     * @param string $signalClass class name of emitter
462
+     * @param string $signalName name of signal
463
+     * @param string|object $slotClass class name of slot
464
+     * @param string $slotName name of slot
465
+     * @return bool
466
+     *
467
+     * This function makes it very easy to connect to use hooks.
468
+     *
469
+     * TODO: write example
470
+     * @since 4.0.0
471
+     */
472
+    static public function connectHook($signalClass, $signalName, $slotClass, $slotName ) {
473
+        return(\OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName ));
474
+    }
475
+
476
+    /**
477
+     * Emits a signal. To get data from the slot use references!
478
+     * @param string $signalclass class name of emitter
479
+     * @param string $signalname name of signal
480
+     * @param array $params default: array() array with additional data
481
+     * @return bool true if slots exists or false if not
482
+     *
483
+     * TODO: write example
484
+     * @since 4.0.0
485
+     */
486
+    static public function emitHook( $signalclass, $signalname, $params = array()) {
487
+        return(\OC_Hook::emit( $signalclass, $signalname, $params ));
488
+    }
489
+
490
+    /**
491
+     * Cached encrypted CSRF token. Some static unit-tests of ownCloud compare
492
+     * multiple OC_Template elements which invoke `callRegister`. If the value
493
+     * would not be cached these unit-tests would fail.
494
+     * @var string
495
+     */
496
+    private static $token = '';
497
+
498
+    /**
499
+     * Register an get/post call. This is important to prevent CSRF attacks
500
+     * @since 4.5.0
501
+     */
502
+    public static function callRegister() {
503
+        if(self::$token === '') {
504
+            self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue();
505
+        }
506
+        return self::$token;
507
+    }
508
+
509
+    /**
510
+     * Check an ajax get/post call if the request token is valid. exit if not.
511
+     * @since 4.5.0
512
+     * @deprecated 9.0.0 Use annotations based on the app framework.
513
+     */
514
+    public static function callCheck() {
515
+        if(!\OC::$server->getRequest()->passesStrictCookieCheck()) {
516
+            header('Location: '.\OC::$WEBROOT);
517
+            exit();
518
+        }
519
+
520
+        if (!(\OC::$server->getRequest()->passesCSRFCheck())) {
521
+            exit();
522
+        }
523
+    }
524
+
525
+    /**
526
+     * Used to sanitize HTML
527
+     *
528
+     * This function is used to sanitize HTML and should be applied on any
529
+     * string or array of strings before displaying it on a web page.
530
+     *
531
+     * @param string|array $value
532
+     * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter.
533
+     * @since 4.5.0
534
+     */
535
+    public static function sanitizeHTML($value) {
536
+        return \OC_Util::sanitizeHTML($value);
537
+    }
538
+
539
+    /**
540
+     * Public function to encode url parameters
541
+     *
542
+     * This function is used to encode path to file before output.
543
+     * Encoding is done according to RFC 3986 with one exception:
544
+     * Character '/' is preserved as is.
545
+     *
546
+     * @param string $component part of URI to encode
547
+     * @return string
548
+     * @since 6.0.0
549
+     */
550
+    public static function encodePath($component) {
551
+        return(\OC_Util::encodePath($component));
552
+    }
553
+
554
+    /**
555
+     * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.
556
+     *
557
+     * @param array $input The array to work on
558
+     * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default)
559
+     * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
560
+     * @return array
561
+     * @since 4.5.0
562
+     */
563
+    public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') {
564
+        return(\OC_Helper::mb_array_change_key_case($input, $case, $encoding));
565
+    }
566
+
567
+    /**
568
+     * replaces a copy of string delimited by the start and (optionally) length parameters with the string given in replacement.
569
+     *
570
+     * @param string $string The input string. Opposite to the PHP build-in function does not accept an array.
571
+     * @param string $replacement The replacement string.
572
+     * @param int $start If start is positive, the replacing will begin at the start'th offset into string. If start is negative, the replacing will begin at the start'th character from the end of string.
573
+     * @param int $length Length of the part to be replaced
574
+     * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
575
+     * @return string
576
+     * @since 4.5.0
577
+     * @deprecated 8.2.0 Use substr_replace() instead.
578
+     */
579
+    public static function mb_substr_replace($string, $replacement, $start, $length = null, $encoding = 'UTF-8') {
580
+        return substr_replace($string, $replacement, $start, $length);
581
+    }
582
+
583
+    /**
584
+     * Replace all occurrences of the search string with the replacement string
585
+     *
586
+     * @param string $search The value being searched for, otherwise known as the needle. String.
587
+     * @param string $replace The replacement string.
588
+     * @param string $subject The string or array being searched and replaced on, otherwise known as the haystack.
589
+     * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
590
+     * @param int $count If passed, this will be set to the number of replacements performed.
591
+     * @return string
592
+     * @since 4.5.0
593
+     * @deprecated 8.2.0 Use str_replace() instead.
594
+     */
595
+    public static function mb_str_replace($search, $replace, $subject, $encoding = 'UTF-8', &$count = null) {
596
+        return str_replace($search, $replace, $subject, $count);
597
+    }
598
+
599
+    /**
600
+     * performs a search in a nested array
601
+     *
602
+     * @param array $haystack the array to be searched
603
+     * @param string $needle the search string
604
+     * @param int $index optional, only search this key name
605
+     * @return mixed the key of the matching field, otherwise false
606
+     * @since 4.5.0
607
+     */
608
+    public static function recursiveArraySearch($haystack, $needle, $index = null) {
609
+        return(\OC_Helper::recursiveArraySearch($haystack, $needle, $index));
610
+    }
611
+
612
+    /**
613
+     * calculates the maximum upload size respecting system settings, free space and user quota
614
+     *
615
+     * @param string $dir the current folder where the user currently operates
616
+     * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly
617
+     * @return int number of bytes representing
618
+     * @since 5.0.0
619
+     */
620
+    public static function maxUploadFilesize($dir, $free = null) {
621
+        return \OC_Helper::maxUploadFilesize($dir, $free);
622
+    }
623
+
624
+    /**
625
+     * Calculate free space left within user quota
626
+     * @param string $dir the current folder where the user currently operates
627
+     * @return int number of bytes representing
628
+     * @since 7.0.0
629
+     */
630
+    public static function freeSpace($dir) {
631
+        return \OC_Helper::freeSpace($dir);
632
+    }
633
+
634
+    /**
635
+     * Calculate PHP upload limit
636
+     *
637
+     * @return int number of bytes representing
638
+     * @since 7.0.0
639
+     */
640
+    public static function uploadLimit() {
641
+        return \OC_Helper::uploadLimit();
642
+    }
643
+
644
+    /**
645
+     * Returns whether the given file name is valid
646
+     * @param string $file file name to check
647
+     * @return bool true if the file name is valid, false otherwise
648
+     * @deprecated 8.1.0 use \OC\Files\View::verifyPath()
649
+     * @since 7.0.0
650
+     */
651
+    public static function isValidFileName($file) {
652
+        return \OC_Util::isValidFileName($file);
653
+    }
654
+
655
+    /**
656
+     * Generates a cryptographic secure pseudo-random string
657
+     * @param int $length of the random string
658
+     * @return string
659
+     * @deprecated 8.0.0 Use \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate($length); instead
660
+     * @since 7.0.0
661
+     */
662
+    public static function generateRandomBytes($length = 30) {
663
+        return \OC::$server->getSecureRandom()->generate($length, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS);
664
+    }
665
+
666
+    /**
667
+     * Compare two strings to provide a natural sort
668
+     * @param string $a first string to compare
669
+     * @param string $b second string to compare
670
+     * @return -1 if $b comes before $a, 1 if $a comes before $b
671
+     * or 0 if the strings are identical
672
+     * @since 7.0.0
673
+     */
674
+    public static function naturalSortCompare($a, $b) {
675
+        return \OC\NaturalSort::getInstance()->compare($a, $b);
676
+    }
677
+
678
+    /**
679
+     * check if a password is required for each public link
680
+     * @return boolean
681
+     * @since 7.0.0
682
+     */
683
+    public static function isPublicLinkPasswordRequired() {
684
+        return \OC_Util::isPublicLinkPasswordRequired();
685
+    }
686
+
687
+    /**
688
+     * check if share API enforces a default expire date
689
+     * @return boolean
690
+     * @since 8.0.0
691
+     */
692
+    public static function isDefaultExpireDateEnforced() {
693
+        return \OC_Util::isDefaultExpireDateEnforced();
694
+    }
695
+
696
+    protected static $needUpgradeCache = null;
697
+
698
+    /**
699
+     * Checks whether the current version needs upgrade.
700
+     *
701
+     * @return bool true if upgrade is needed, false otherwise
702
+     * @since 7.0.0
703
+     */
704
+    public static function needUpgrade() {
705
+        if (!isset(self::$needUpgradeCache)) {
706
+            self::$needUpgradeCache=\OC_Util::needUpgrade(\OC::$server->getSystemConfig());
707
+        }		
708
+        return self::$needUpgradeCache;
709
+    }
710 710
 }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -58,11 +58,11 @@  discard block
 block discarded – undo
58 58
  */
59 59
 class Util {
60 60
 	// consts for Logging
61
-	const DEBUG=0;
62
-	const INFO=1;
63
-	const WARN=2;
64
-	const ERROR=3;
65
-	const FATAL=4;
61
+	const DEBUG = 0;
62
+	const INFO = 1;
63
+	const WARN = 2;
64
+	const ERROR = 3;
65
+	const FATAL = 4;
66 66
 
67 67
 	/** \OCP\Share\IManager */
68 68
 	private static $shareManager;
@@ -118,11 +118,11 @@  discard block
 block discarded – undo
118 118
 		$message->setSubject($subject);
119 119
 		$message->setPlainBody($mailtext);
120 120
 		$message->setFrom([$fromaddress => $fromname]);
121
-		if($html === 1) {
121
+		if ($html === 1) {
122 122
 			$message->setHTMLBody($altbody);
123 123
 		}
124 124
 
125
-		if($altbody === '') {
125
+		if ($altbody === '') {
126 126
 			$message->setHTMLBody($mailtext);
127 127
 			$message->setPlainBody('');
128 128
 		} else {
@@ -130,14 +130,14 @@  discard block
 block discarded – undo
130 130
 			$message->setPlainBody($altbody);
131 131
 		}
132 132
 
133
-		if(!empty($ccaddress)) {
134
-			if(!empty($ccname)) {
133
+		if (!empty($ccaddress)) {
134
+			if (!empty($ccname)) {
135 135
 				$message->setCc([$ccaddress => $ccname]);
136 136
 			} else {
137 137
 				$message->setCc([$ccaddress]);
138 138
 			}
139 139
 		}
140
-		if(!empty($bcc)) {
140
+		if (!empty($bcc)) {
141 141
 			$message->setBcc([$bcc]);
142 142
 		}
143 143
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 	 * @param int $level
152 152
 	 * @since 4.0.0
153 153
 	 */
154
-	public static function writeLog( $app, $message, $level ) {
154
+	public static function writeLog($app, $message, $level) {
155 155
 		$context = ['app' => $app];
156 156
 		\OC::$server->getLogger()->log($level, $message, $context);
157 157
 	}
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 	 * @since ....0.0 - parameter $level was added in 7.0.0
165 165
 	 * @deprecated 8.2.0 use logException of \OCP\ILogger
166 166
 	 */
167
-	public static function logException( $app, \Exception $ex, $level = \OCP\Util::FATAL ) {
167
+	public static function logException($app, \Exception $ex, $level = \OCP\Util::FATAL) {
168 168
 		\OC::$server->getLogger()->logException($ex, ['app' => $app]);
169 169
 	}
170 170
 
@@ -205,8 +205,8 @@  discard block
 block discarded – undo
205 205
 	 * @param string $file
206 206
 	 * @since 4.0.0
207 207
 	 */
208
-	public static function addStyle( $application, $file = null ) {
209
-		\OC_Util::addStyle( $application, $file );
208
+	public static function addStyle($application, $file = null) {
209
+		\OC_Util::addStyle($application, $file);
210 210
 	}
211 211
 
212 212
 	/**
@@ -215,8 +215,8 @@  discard block
 block discarded – undo
215 215
 	 * @param string $file
216 216
 	 * @since 4.0.0
217 217
 	 */
218
-	public static function addScript( $application, $file = null ) {
219
-		\OC_Util::addScript( $application, $file );
218
+	public static function addScript($application, $file = null) {
219
+		\OC_Util::addScript($application, $file);
220 220
 	}
221 221
 
222 222
 	/**
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 	 * @param string $text the text content for the element
239 239
 	 * @since 4.0.0
240 240
 	 */
241
-	public static function addHeader($tag, $attributes, $text=null) {
241
+	public static function addHeader($tag, $attributes, $text = null) {
242 242
 		\OC_Util::addHeader($tag, $attributes, $text);
243 243
 	}
244 244
 
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 	 * @deprecated 8.0.0 Use \OC::$server->query('DateTimeFormatter') instead
253 253
 	 * @since 4.0.0
254 254
 	 */
255
-	public static function formatDate($timestamp, $dateOnly=false, $timeZone = null) {
255
+	public static function formatDate($timestamp, $dateOnly = false, $timeZone = null) {
256 256
 		return(\OC_Util::formatDate($timestamp, $dateOnly, $timeZone));
257 257
 	}
258 258
 
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 	 * @return string the url
277 277
 	 * @since 4.0.0 - parameter $args was added in 4.5.0
278 278
 	 */
279
-	public static function linkToAbsolute( $app, $file, $args = array() ) {
279
+	public static function linkToAbsolute($app, $file, $args = array()) {
280 280
 		$urlGenerator = \OC::$server->getURLGenerator();
281 281
 		return $urlGenerator->getAbsoluteURL(
282 282
 			$urlGenerator->linkTo($app, $file, $args)
@@ -289,11 +289,11 @@  discard block
 block discarded – undo
289 289
 	 * @return string the url
290 290
 	 * @since 4.0.0
291 291
 	 */
292
-	public static function linkToRemote( $service ) {
292
+	public static function linkToRemote($service) {
293 293
 		$urlGenerator = \OC::$server->getURLGenerator();
294
-		$remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service;
294
+		$remoteBase = $urlGenerator->linkTo('', 'remote.php').'/'.$service;
295 295
 		return $urlGenerator->getAbsoluteURL(
296
-			$remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '')
296
+			$remoteBase.(($service[strlen($service) - 1] != '/') ? '/' : '')
297 297
 		);
298 298
 	}
299 299
 
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 	 * @deprecated 8.1.0 Use \OC::$server->getURLGenerator()->linkToRoute($route, $parameters)
317 317
 	 * @since 5.0.0
318 318
 	 */
319
-	public static function linkToRoute( $route, $parameters = array() ) {
319
+	public static function linkToRoute($route, $parameters = array()) {
320 320
 		return \OC::$server->getURLGenerator()->linkToRoute($route, $parameters);
321 321
 	}
322 322
 
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 	 * @deprecated 8.1.0 Use \OC::$server->getURLGenerator()->linkTo($app, $file, $args)
331 331
 	 * @since 4.0.0 - parameter $args was added in 4.5.0
332 332
 	 */
333
-	public static function linkTo( $app, $file, $args = array() ) {
333
+	public static function linkTo($app, $file, $args = array()) {
334 334
 		return \OC::$server->getURLGenerator()->linkTo($app, $file, $args);
335 335
 	}
336 336
 
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
 	 * @deprecated 8.1.0 Use \OC::$server->getURLGenerator()->imagePath($app, $image)
430 430
 	 * @since 4.0.0
431 431
 	 */
432
-	public static function imagePath( $app, $image ) {
432
+	public static function imagePath($app, $image) {
433 433
 		return \OC::$server->getURLGenerator()->imagePath($app, $image);
434 434
 	}
435 435
 
@@ -439,8 +439,8 @@  discard block
 block discarded – undo
439 439
 	 * @return string a human readable file size
440 440
 	 * @since 4.0.0
441 441
 	 */
442
-	public static function humanFileSize( $bytes ) {
443
-		return(\OC_Helper::humanFileSize( $bytes ));
442
+	public static function humanFileSize($bytes) {
443
+		return(\OC_Helper::humanFileSize($bytes));
444 444
 	}
445 445
 
446 446
 	/**
@@ -451,8 +451,8 @@  discard block
 block discarded – undo
451 451
 	 * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418
452 452
 	 * @since 4.0.0
453 453
 	 */
454
-	public static function computerFileSize( $str ) {
455
-		return(\OC_Helper::computerFileSize( $str ));
454
+	public static function computerFileSize($str) {
455
+		return(\OC_Helper::computerFileSize($str));
456 456
 	}
457 457
 
458 458
 	/**
@@ -469,8 +469,8 @@  discard block
 block discarded – undo
469 469
 	 * TODO: write example
470 470
 	 * @since 4.0.0
471 471
 	 */
472
-	static public function connectHook($signalClass, $signalName, $slotClass, $slotName ) {
473
-		return(\OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName ));
472
+	static public function connectHook($signalClass, $signalName, $slotClass, $slotName) {
473
+		return(\OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName));
474 474
 	}
475 475
 
476 476
 	/**
@@ -483,8 +483,8 @@  discard block
 block discarded – undo
483 483
 	 * TODO: write example
484 484
 	 * @since 4.0.0
485 485
 	 */
486
-	static public function emitHook( $signalclass, $signalname, $params = array()) {
487
-		return(\OC_Hook::emit( $signalclass, $signalname, $params ));
486
+	static public function emitHook($signalclass, $signalname, $params = array()) {
487
+		return(\OC_Hook::emit($signalclass, $signalname, $params));
488 488
 	}
489 489
 
490 490
 	/**
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
 	 * @since 4.5.0
501 501
 	 */
502 502
 	public static function callRegister() {
503
-		if(self::$token === '') {
503
+		if (self::$token === '') {
504 504
 			self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue();
505 505
 		}
506 506
 		return self::$token;
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
 	 * @deprecated 9.0.0 Use annotations based on the app framework.
513 513
 	 */
514 514
 	public static function callCheck() {
515
-		if(!\OC::$server->getRequest()->passesStrictCookieCheck()) {
515
+		if (!\OC::$server->getRequest()->passesStrictCookieCheck()) {
516 516
 			header('Location: '.\OC::$WEBROOT);
517 517
 			exit();
518 518
 		}
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 	 */
704 704
 	public static function needUpgrade() {
705 705
 		if (!isset(self::$needUpgradeCache)) {
706
-			self::$needUpgradeCache=\OC_Util::needUpgrade(\OC::$server->getSystemConfig());
706
+			self::$needUpgradeCache = \OC_Util::needUpgrade(\OC::$server->getSystemConfig());
707 707
 		}		
708 708
 		return self::$needUpgradeCache;
709 709
 	}
Please login to merge, or discard this patch.
lib/private/Files/View.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 	 * and does not take the chroot into account )
201 201
 	 *
202 202
 	 * @param string $path
203
-	 * @return \OCP\Files\Mount\IMountPoint
203
+	 * @return Mount\MountPoint|null
204 204
 	 */
205 205
 	public function getMount($path) {
206 206
 		return Filesystem::getMountManager()->find($this->getAbsolutePath($path));
@@ -963,7 +963,7 @@  discard block
 block discarded – undo
963 963
 
964 964
 	/**
965 965
 	 * @param string $path
966
-	 * @return bool|string
966
+	 * @return string|false
967 967
 	 * @throws \OCP\Files\InvalidPathException
968 968
 	 */
969 969
 	public function toTmpFile($path) {
@@ -1078,7 +1078,7 @@  discard block
 block discarded – undo
1078 1078
 	 * @param string $path
1079 1079
 	 * @param array $hooks (optional)
1080 1080
 	 * @param mixed $extraParam (optional)
1081
-	 * @return mixed
1081
+	 * @return string
1082 1082
 	 * @throws \Exception
1083 1083
 	 *
1084 1084
 	 * This method takes requests for basic filesystem functions (e.g. reading & writing
@@ -2086,7 +2086,7 @@  discard block
 block discarded – undo
2086 2086
 
2087 2087
 	/**
2088 2088
 	 * @param string $filename
2089
-	 * @return array
2089
+	 * @return string[]
2090 2090
 	 * @throws \OC\User\NoUserException
2091 2091
 	 * @throws NotFoundException
2092 2092
 	 */
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
 			$path = '/';
126 126
 		}
127 127
 		if ($path[0] !== '/') {
128
-			$path = '/' . $path;
128
+			$path = '/'.$path;
129 129
 		}
130
-		return $this->fakeRoot . $path;
130
+		return $this->fakeRoot.$path;
131 131
 	}
132 132
 
133 133
 	/**
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 	public function chroot($fakeRoot) {
140 140
 		if (!$fakeRoot == '') {
141 141
 			if ($fakeRoot[0] !== '/') {
142
-				$fakeRoot = '/' . $fakeRoot;
142
+				$fakeRoot = '/'.$fakeRoot;
143 143
 			}
144 144
 		}
145 145
 		$this->fakeRoot = $fakeRoot;
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 		}
172 172
 
173 173
 		// missing slashes can cause wrong matches!
174
-		$root = rtrim($this->fakeRoot, '/') . '/';
174
+		$root = rtrim($this->fakeRoot, '/').'/';
175 175
 
176 176
 		if (strpos($path, $root) !== 0) {
177 177
 			return null;
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 		if ($mount instanceof MoveableMount) {
278 278
 			// cut of /user/files to get the relative path to data/user/files
279 279
 			$pathParts = explode('/', $path, 4);
280
-			$relPath = '/' . $pathParts[3];
280
+			$relPath = '/'.$pathParts[3];
281 281
 			$this->lockFile($relPath, ILockingProvider::LOCK_SHARED, true);
282 282
 			\OC_Hook::emit(
283 283
 				Filesystem::CLASSNAME, "umount",
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
 		}
689 689
 		$postFix = (substr($path, -1, 1) === '/') ? '/' : '';
690 690
 		$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
691
-		$mount = Filesystem::getMountManager()->find($absolutePath . $postFix);
691
+		$mount = Filesystem::getMountManager()->find($absolutePath.$postFix);
692 692
 		if ($mount and $mount->getInternalPath($absolutePath) === '') {
693 693
 			return $this->removeMount($mount, $absolutePath);
694 694
 		}
@@ -954,7 +954,7 @@  discard block
 block discarded – undo
954 954
 				$hooks[] = 'write';
955 955
 				break;
956 956
 			default:
957
-				\OCP\Util::writeLog('core', 'invalid mode (' . $mode . ') for ' . $path, \OCP\Util::ERROR);
957
+				\OCP\Util::writeLog('core', 'invalid mode ('.$mode.') for '.$path, \OCP\Util::ERROR);
958 958
 		}
959 959
 
960 960
 		if ($mode !== 'r' && $mode !== 'w') {
@@ -1058,7 +1058,7 @@  discard block
 block discarded – undo
1058 1058
 					array(Filesystem::signal_param_path => $this->getHookPath($path))
1059 1059
 				);
1060 1060
 			}
1061
-			list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix);
1061
+			list($storage, $internalPath) = Filesystem::resolvePath($absolutePath.$postFix);
1062 1062
 			if ($storage) {
1063 1063
 				$result = $storage->hash($type, $internalPath, $raw);
1064 1064
 				return $result;
@@ -1109,7 +1109,7 @@  discard block
 block discarded – undo
1109 1109
 
1110 1110
 			$run = $this->runHooks($hooks, $path);
1111 1111
 			/** @var \OC\Files\Storage\Storage $storage */
1112
-			list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix);
1112
+			list($storage, $internalPath) = Filesystem::resolvePath($absolutePath.$postFix);
1113 1113
 			if ($run and $storage) {
1114 1114
 				if (in_array('write', $hooks) || in_array('delete', $hooks)) {
1115 1115
 					$this->changeLock($path, ILockingProvider::LOCK_EXCLUSIVE);
@@ -1148,7 +1148,7 @@  discard block
 block discarded – undo
1148 1148
 					$unlockLater = true;
1149 1149
 					// make sure our unlocking callback will still be called if connection is aborted
1150 1150
 					ignore_user_abort(true);
1151
-					$result = CallbackWrapper::wrap($result, null, null, function () use ($hooks, $path) {
1151
+					$result = CallbackWrapper::wrap($result, null, null, function() use ($hooks, $path) {
1152 1152
 						if (in_array('write', $hooks)) {
1153 1153
 							$this->unlockFile($path, ILockingProvider::LOCK_EXCLUSIVE);
1154 1154
 						} else if (in_array('read', $hooks)) {
@@ -1209,7 +1209,7 @@  discard block
 block discarded – undo
1209 1209
 			return true;
1210 1210
 		}
1211 1211
 
1212
-		return (strlen($fullPath) > strlen($defaultRoot)) && (substr($fullPath, 0, strlen($defaultRoot) + 1) === $defaultRoot . '/');
1212
+		return (strlen($fullPath) > strlen($defaultRoot)) && (substr($fullPath, 0, strlen($defaultRoot) + 1) === $defaultRoot.'/');
1213 1213
 	}
1214 1214
 
1215 1215
 	/**
@@ -1228,7 +1228,7 @@  discard block
 block discarded – undo
1228 1228
 				if ($hook != 'read') {
1229 1229
 					\OC_Hook::emit(
1230 1230
 						Filesystem::CLASSNAME,
1231
-						$prefix . $hook,
1231
+						$prefix.$hook,
1232 1232
 						array(
1233 1233
 							Filesystem::signal_param_run => &$run,
1234 1234
 							Filesystem::signal_param_path => $path
@@ -1237,7 +1237,7 @@  discard block
 block discarded – undo
1237 1237
 				} elseif (!$post) {
1238 1238
 					\OC_Hook::emit(
1239 1239
 						Filesystem::CLASSNAME,
1240
-						$prefix . $hook,
1240
+						$prefix.$hook,
1241 1241
 						array(
1242 1242
 							Filesystem::signal_param_path => $path
1243 1243
 						)
@@ -1332,7 +1332,7 @@  discard block
 block discarded – undo
1332 1332
 			return $this->getPartFileInfo($path);
1333 1333
 		}
1334 1334
 		$relativePath = $path;
1335
-		$path = Filesystem::normalizePath($this->fakeRoot . '/' . $path);
1335
+		$path = Filesystem::normalizePath($this->fakeRoot.'/'.$path);
1336 1336
 
1337 1337
 		$mount = Filesystem::getMountManager()->find($path);
1338 1338
 		$storage = $mount->getStorage();
@@ -1356,7 +1356,7 @@  discard block
 block discarded – undo
1356 1356
 					//add the sizes of other mount points to the folder
1357 1357
 					$extOnly = ($includeMountPoints === 'ext');
1358 1358
 					$mounts = Filesystem::getMountManager()->findIn($path);
1359
-					$info->setSubMounts(array_filter($mounts, function (IMountPoint $mount) use ($extOnly) {
1359
+					$info->setSubMounts(array_filter($mounts, function(IMountPoint $mount) use ($extOnly) {
1360 1360
 						$subStorage = $mount->getStorage();
1361 1361
 						return !($extOnly && $subStorage instanceof \OCA\Files_Sharing\SharedStorage);
1362 1362
 					}));
@@ -1403,12 +1403,12 @@  discard block
 block discarded – undo
1403 1403
 			/**
1404 1404
 			 * @var \OC\Files\FileInfo[] $files
1405 1405
 			 */
1406
-			$files = array_map(function (ICacheEntry $content) use ($path, $storage, $mount, $sharingDisabled) {
1406
+			$files = array_map(function(ICacheEntry $content) use ($path, $storage, $mount, $sharingDisabled) {
1407 1407
 				if ($sharingDisabled) {
1408 1408
 					$content['permissions'] = $content['permissions'] & ~\OCP\Constants::PERMISSION_SHARE;
1409 1409
 				}
1410 1410
 				$owner = $this->getUserObjectForOwner($storage->getOwner($content['path']));
1411
-				return new FileInfo($path . '/' . $content['name'], $storage, $content['path'], $content, $mount, $owner);
1411
+				return new FileInfo($path.'/'.$content['name'], $storage, $content['path'], $content, $mount, $owner);
1412 1412
 			}, $contents);
1413 1413
 
1414 1414
 			//add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
@@ -1433,8 +1433,8 @@  discard block
 block discarded – undo
1433 1433
 							// sometimes when the storage is not available it can be any exception
1434 1434
 							\OCP\Util::writeLog(
1435 1435
 								'core',
1436
-								'Exception while scanning storage "' . $subStorage->getId() . '": ' .
1437
-								get_class($e) . ': ' . $e->getMessage(),
1436
+								'Exception while scanning storage "'.$subStorage->getId().'": '.
1437
+								get_class($e).': '.$e->getMessage(),
1438 1438
 								\OCP\Util::ERROR
1439 1439
 							);
1440 1440
 							continue;
@@ -1471,7 +1471,7 @@  discard block
 block discarded – undo
1471 1471
 									break;
1472 1472
 								}
1473 1473
 							}
1474
-							$rootEntry['path'] = substr(Filesystem::normalizePath($path . '/' . $rootEntry['name']), strlen($user) + 2); // full path without /$user/
1474
+							$rootEntry['path'] = substr(Filesystem::normalizePath($path.'/'.$rootEntry['name']), strlen($user) + 2); // full path without /$user/
1475 1475
 
1476 1476
 							// if sharing was disabled for the user we remove the share permissions
1477 1477
 							if (\OCP\Util::isSharingDisabledForUser()) {
@@ -1479,14 +1479,14 @@  discard block
 block discarded – undo
1479 1479
 							}
1480 1480
 
1481 1481
 							$owner = $this->getUserObjectForOwner($subStorage->getOwner(''));
1482
-							$files[] = new FileInfo($path . '/' . $rootEntry['name'], $subStorage, '', $rootEntry, $mount, $owner);
1482
+							$files[] = new FileInfo($path.'/'.$rootEntry['name'], $subStorage, '', $rootEntry, $mount, $owner);
1483 1483
 						}
1484 1484
 					}
1485 1485
 				}
1486 1486
 			}
1487 1487
 
1488 1488
 			if ($mimetype_filter) {
1489
-				$files = array_filter($files, function (FileInfo $file) use ($mimetype_filter) {
1489
+				$files = array_filter($files, function(FileInfo $file) use ($mimetype_filter) {
1490 1490
 					if (strpos($mimetype_filter, '/')) {
1491 1491
 						return $file->getMimetype() === $mimetype_filter;
1492 1492
 					} else {
@@ -1515,7 +1515,7 @@  discard block
 block discarded – undo
1515 1515
 		if ($data instanceof FileInfo) {
1516 1516
 			$data = $data->getData();
1517 1517
 		}
1518
-		$path = Filesystem::normalizePath($this->fakeRoot . '/' . $path);
1518
+		$path = Filesystem::normalizePath($this->fakeRoot.'/'.$path);
1519 1519
 		/**
1520 1520
 		 * @var \OC\Files\Storage\Storage $storage
1521 1521
 		 * @var string $internalPath
@@ -1542,7 +1542,7 @@  discard block
 block discarded – undo
1542 1542
 	 * @return FileInfo[]
1543 1543
 	 */
1544 1544
 	public function search($query) {
1545
-		return $this->searchCommon('search', array('%' . $query . '%'));
1545
+		return $this->searchCommon('search', array('%'.$query.'%'));
1546 1546
 	}
1547 1547
 
1548 1548
 	/**
@@ -1593,10 +1593,10 @@  discard block
 block discarded – undo
1593 1593
 
1594 1594
 			$results = call_user_func_array(array($cache, $method), $args);
1595 1595
 			foreach ($results as $result) {
1596
-				if (substr($mountPoint . $result['path'], 0, $rootLength + 1) === $this->fakeRoot . '/') {
1596
+				if (substr($mountPoint.$result['path'], 0, $rootLength + 1) === $this->fakeRoot.'/') {
1597 1597
 					$internalPath = $result['path'];
1598
-					$path = $mountPoint . $result['path'];
1599
-					$result['path'] = substr($mountPoint . $result['path'], $rootLength);
1598
+					$path = $mountPoint.$result['path'];
1599
+					$result['path'] = substr($mountPoint.$result['path'], $rootLength);
1600 1600
 					$owner = \OC::$server->getUserManager()->get($storage->getOwner($internalPath));
1601 1601
 					$files[] = new FileInfo($path, $storage, $internalPath, $result, $mount, $owner);
1602 1602
 				}
@@ -1614,8 +1614,8 @@  discard block
 block discarded – undo
1614 1614
 					if ($results) {
1615 1615
 						foreach ($results as $result) {
1616 1616
 							$internalPath = $result['path'];
1617
-							$result['path'] = rtrim($relativeMountPoint . $result['path'], '/');
1618
-							$path = rtrim($mountPoint . $internalPath, '/');
1617
+							$result['path'] = rtrim($relativeMountPoint.$result['path'], '/');
1618
+							$path = rtrim($mountPoint.$internalPath, '/');
1619 1619
 							$owner = \OC::$server->getUserManager()->get($storage->getOwner($internalPath));
1620 1620
 							$files[] = new FileInfo($path, $storage, $internalPath, $result, $mount, $owner);
1621 1621
 						}
@@ -1636,7 +1636,7 @@  discard block
 block discarded – undo
1636 1636
 	public function getOwner($path) {
1637 1637
 		$info = $this->getFileInfo($path);
1638 1638
 		if (!$info) {
1639
-			throw new NotFoundException($path . ' not found while trying to get owner');
1639
+			throw new NotFoundException($path.' not found while trying to get owner');
1640 1640
 		}
1641 1641
 		return $info->getOwner()->getUID();
1642 1642
 	}
@@ -1670,7 +1670,7 @@  discard block
 block discarded – undo
1670 1670
 	 * @return string
1671 1671
 	 */
1672 1672
 	public function getPath($id) {
1673
-		$id = (int)$id;
1673
+		$id = (int) $id;
1674 1674
 		$manager = Filesystem::getMountManager();
1675 1675
 		$mounts = $manager->findIn($this->fakeRoot);
1676 1676
 		$mounts[] = $manager->find($this->fakeRoot);
@@ -1685,7 +1685,7 @@  discard block
 block discarded – undo
1685 1685
 				$cache = $mount->getStorage()->getCache();
1686 1686
 				$internalPath = $cache->getPathById($id);
1687 1687
 				if (is_string($internalPath)) {
1688
-					$fullPath = $mount->getMountPoint() . $internalPath;
1688
+					$fullPath = $mount->getMountPoint().$internalPath;
1689 1689
 					if (!is_null($path = $this->getRelativePath($fullPath))) {
1690 1690
 						return $path;
1691 1691
 					}
@@ -1728,10 +1728,10 @@  discard block
 block discarded – undo
1728 1728
 		}
1729 1729
 
1730 1730
 		// note: cannot use the view because the target is already locked
1731
-		$fileId = (int)$targetStorage->getCache()->getId($targetInternalPath);
1731
+		$fileId = (int) $targetStorage->getCache()->getId($targetInternalPath);
1732 1732
 		if ($fileId === -1) {
1733 1733
 			// target might not exist, need to check parent instead
1734
-			$fileId = (int)$targetStorage->getCache()->getId(dirname($targetInternalPath));
1734
+			$fileId = (int) $targetStorage->getCache()->getId(dirname($targetInternalPath));
1735 1735
 		}
1736 1736
 
1737 1737
 		// check if any of the parents were shared by the current owner (include collections)
@@ -1831,7 +1831,7 @@  discard block
 block discarded – undo
1831 1831
 		$resultPath = '';
1832 1832
 		foreach ($parts as $part) {
1833 1833
 			if ($part) {
1834
-				$resultPath .= '/' . $part;
1834
+				$resultPath .= '/'.$part;
1835 1835
 				$result[] = $resultPath;
1836 1836
 			}
1837 1837
 		}
@@ -2081,16 +2081,16 @@  discard block
 block discarded – undo
2081 2081
 	public function getUidAndFilename($filename) {
2082 2082
 		$info = $this->getFileInfo($filename);
2083 2083
 		if (!$info instanceof \OCP\Files\FileInfo) {
2084
-			throw new NotFoundException($this->getAbsolutePath($filename) . ' not found');
2084
+			throw new NotFoundException($this->getAbsolutePath($filename).' not found');
2085 2085
 		}
2086 2086
 		$uid = $info->getOwner()->getUID();
2087 2087
 		if ($uid != \OCP\User::getUser()) {
2088 2088
 			Filesystem::initMountPoints($uid);
2089
-			$ownerView = new View('/' . $uid . '/files');
2089
+			$ownerView = new View('/'.$uid.'/files');
2090 2090
 			try {
2091 2091
 				$filename = $ownerView->getPath($info['fileid']);
2092 2092
 			} catch (NotFoundException $e) {
2093
-				throw new NotFoundException('File with id ' . $info['fileid'] . ' not found for user ' . $uid);
2093
+				throw new NotFoundException('File with id '.$info['fileid'].' not found for user '.$uid);
2094 2094
 			}
2095 2095
 		}
2096 2096
 		return [$uid, $filename];
@@ -2107,7 +2107,7 @@  discard block
 block discarded – undo
2107 2107
 		$directoryParts = array_filter($directoryParts);
2108 2108
 		foreach ($directoryParts as $key => $part) {
2109 2109
 			$currentPathElements = array_slice($directoryParts, 0, $key);
2110
-			$currentPath = '/' . implode('/', $currentPathElements);
2110
+			$currentPath = '/'.implode('/', $currentPathElements);
2111 2111
 			if ($this->is_file($currentPath)) {
2112 2112
 				return false;
2113 2113
 			}
Please login to merge, or discard this patch.
Indentation   +2049 added lines, -2049 removed lines patch added patch discarded remove patch
@@ -84,2053 +84,2053 @@
 block discarded – undo
84 84
  * \OC\Files\Storage\Storage object
85 85
  */
86 86
 class View {
87
-	/** @var string */
88
-	private $fakeRoot = '';
89
-
90
-	/**
91
-	 * @var \OCP\Lock\ILockingProvider
92
-	 */
93
-	private $lockingProvider;
94
-
95
-	private $lockingEnabled;
96
-
97
-	private $updaterEnabled = true;
98
-
99
-	/** @var \OC\User\Manager */
100
-	private $userManager;
101
-
102
-	/** @var \OCP\ILogger */
103
-	private $logger;
104
-
105
-	/**
106
-	 * @param string $root
107
-	 * @throws \Exception If $root contains an invalid path
108
-	 */
109
-	public function __construct($root = '') {
110
-		if (is_null($root)) {
111
-			throw new \InvalidArgumentException('Root can\'t be null');
112
-		}
113
-		if (!Filesystem::isValidPath($root)) {
114
-			throw new \Exception();
115
-		}
116
-
117
-		$this->fakeRoot = $root;
118
-		$this->lockingProvider = \OC::$server->getLockingProvider();
119
-		$this->lockingEnabled = !($this->lockingProvider instanceof \OC\Lock\NoopLockingProvider);
120
-		$this->userManager = \OC::$server->getUserManager();
121
-		$this->logger = \OC::$server->getLogger();
122
-	}
123
-
124
-	public function getAbsolutePath($path = '/') {
125
-		if ($path === null) {
126
-			return null;
127
-		}
128
-		$this->assertPathLength($path);
129
-		if ($path === '') {
130
-			$path = '/';
131
-		}
132
-		if ($path[0] !== '/') {
133
-			$path = '/' . $path;
134
-		}
135
-		return $this->fakeRoot . $path;
136
-	}
137
-
138
-	/**
139
-	 * change the root to a fake root
140
-	 *
141
-	 * @param string $fakeRoot
142
-	 * @return boolean|null
143
-	 */
144
-	public function chroot($fakeRoot) {
145
-		if (!$fakeRoot == '') {
146
-			if ($fakeRoot[0] !== '/') {
147
-				$fakeRoot = '/' . $fakeRoot;
148
-			}
149
-		}
150
-		$this->fakeRoot = $fakeRoot;
151
-	}
152
-
153
-	/**
154
-	 * get the fake root
155
-	 *
156
-	 * @return string
157
-	 */
158
-	public function getRoot() {
159
-		return $this->fakeRoot;
160
-	}
161
-
162
-	/**
163
-	 * get path relative to the root of the view
164
-	 *
165
-	 * @param string $path
166
-	 * @return string
167
-	 */
168
-	public function getRelativePath($path) {
169
-		$this->assertPathLength($path);
170
-		if ($this->fakeRoot == '') {
171
-			return $path;
172
-		}
173
-
174
-		if (rtrim($path, '/') === rtrim($this->fakeRoot, '/')) {
175
-			return '/';
176
-		}
177
-
178
-		// missing slashes can cause wrong matches!
179
-		$root = rtrim($this->fakeRoot, '/') . '/';
180
-
181
-		if (strpos($path, $root) !== 0) {
182
-			return null;
183
-		} else {
184
-			$path = substr($path, strlen($this->fakeRoot));
185
-			if (strlen($path) === 0) {
186
-				return '/';
187
-			} else {
188
-				return $path;
189
-			}
190
-		}
191
-	}
192
-
193
-	/**
194
-	 * get the mountpoint of the storage object for a path
195
-	 * ( note: because a storage is not always mounted inside the fakeroot, the
196
-	 * returned mountpoint is relative to the absolute root of the filesystem
197
-	 * and does not take the chroot into account )
198
-	 *
199
-	 * @param string $path
200
-	 * @return string
201
-	 */
202
-	public function getMountPoint($path) {
203
-		return Filesystem::getMountPoint($this->getAbsolutePath($path));
204
-	}
205
-
206
-	/**
207
-	 * get the mountpoint of the storage object for a path
208
-	 * ( note: because a storage is not always mounted inside the fakeroot, the
209
-	 * returned mountpoint is relative to the absolute root of the filesystem
210
-	 * and does not take the chroot into account )
211
-	 *
212
-	 * @param string $path
213
-	 * @return \OCP\Files\Mount\IMountPoint
214
-	 */
215
-	public function getMount($path) {
216
-		return Filesystem::getMountManager()->find($this->getAbsolutePath($path));
217
-	}
218
-
219
-	/**
220
-	 * resolve a path to a storage and internal path
221
-	 *
222
-	 * @param string $path
223
-	 * @return array an array consisting of the storage and the internal path
224
-	 */
225
-	public function resolvePath($path) {
226
-		$a = $this->getAbsolutePath($path);
227
-		$p = Filesystem::normalizePath($a);
228
-		return Filesystem::resolvePath($p);
229
-	}
230
-
231
-	/**
232
-	 * return the path to a local version of the file
233
-	 * we need this because we can't know if a file is stored local or not from
234
-	 * outside the filestorage and for some purposes a local file is needed
235
-	 *
236
-	 * @param string $path
237
-	 * @return string
238
-	 */
239
-	public function getLocalFile($path) {
240
-		$parent = substr($path, 0, strrpos($path, '/'));
241
-		$path = $this->getAbsolutePath($path);
242
-		list($storage, $internalPath) = Filesystem::resolvePath($path);
243
-		if (Filesystem::isValidPath($parent) and $storage) {
244
-			return $storage->getLocalFile($internalPath);
245
-		} else {
246
-			return null;
247
-		}
248
-	}
249
-
250
-	/**
251
-	 * @param string $path
252
-	 * @return string
253
-	 */
254
-	public function getLocalFolder($path) {
255
-		$parent = substr($path, 0, strrpos($path, '/'));
256
-		$path = $this->getAbsolutePath($path);
257
-		list($storage, $internalPath) = Filesystem::resolvePath($path);
258
-		if (Filesystem::isValidPath($parent) and $storage) {
259
-			return $storage->getLocalFolder($internalPath);
260
-		} else {
261
-			return null;
262
-		}
263
-	}
264
-
265
-	/**
266
-	 * the following functions operate with arguments and return values identical
267
-	 * to those of their PHP built-in equivalents. Mostly they are merely wrappers
268
-	 * for \OC\Files\Storage\Storage via basicOperation().
269
-	 */
270
-	public function mkdir($path) {
271
-		return $this->basicOperation('mkdir', $path, array('create', 'write'));
272
-	}
273
-
274
-	/**
275
-	 * remove mount point
276
-	 *
277
-	 * @param \OC\Files\Mount\MoveableMount $mount
278
-	 * @param string $path relative to data/
279
-	 * @return boolean
280
-	 */
281
-	protected function removeMount($mount, $path) {
282
-		if ($mount instanceof MoveableMount) {
283
-			// cut of /user/files to get the relative path to data/user/files
284
-			$pathParts = explode('/', $path, 4);
285
-			$relPath = '/' . $pathParts[3];
286
-			$this->lockFile($relPath, ILockingProvider::LOCK_SHARED, true);
287
-			\OC_Hook::emit(
288
-				Filesystem::CLASSNAME, "umount",
289
-				array(Filesystem::signal_param_path => $relPath)
290
-			);
291
-			$this->changeLock($relPath, ILockingProvider::LOCK_EXCLUSIVE, true);
292
-			$result = $mount->removeMount();
293
-			$this->changeLock($relPath, ILockingProvider::LOCK_SHARED, true);
294
-			if ($result) {
295
-				\OC_Hook::emit(
296
-					Filesystem::CLASSNAME, "post_umount",
297
-					array(Filesystem::signal_param_path => $relPath)
298
-				);
299
-			}
300
-			$this->unlockFile($relPath, ILockingProvider::LOCK_SHARED, true);
301
-			return $result;
302
-		} else {
303
-			// do not allow deleting the storage's root / the mount point
304
-			// because for some storages it might delete the whole contents
305
-			// but isn't supposed to work that way
306
-			return false;
307
-		}
308
-	}
309
-
310
-	public function disableCacheUpdate() {
311
-		$this->updaterEnabled = false;
312
-	}
313
-
314
-	public function enableCacheUpdate() {
315
-		$this->updaterEnabled = true;
316
-	}
317
-
318
-	protected function writeUpdate(Storage $storage, $internalPath, $time = null) {
319
-		if ($this->updaterEnabled) {
320
-			if (is_null($time)) {
321
-				$time = time();
322
-			}
323
-			$storage->getUpdater()->update($internalPath, $time);
324
-		}
325
-	}
326
-
327
-	protected function removeUpdate(Storage $storage, $internalPath) {
328
-		if ($this->updaterEnabled) {
329
-			$storage->getUpdater()->remove($internalPath);
330
-		}
331
-	}
332
-
333
-	protected function renameUpdate(Storage $sourceStorage, Storage $targetStorage, $sourceInternalPath, $targetInternalPath) {
334
-		if ($this->updaterEnabled) {
335
-			$targetStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
336
-		}
337
-	}
338
-
339
-	/**
340
-	 * @param string $path
341
-	 * @return bool|mixed
342
-	 */
343
-	public function rmdir($path) {
344
-		$absolutePath = $this->getAbsolutePath($path);
345
-		$mount = Filesystem::getMountManager()->find($absolutePath);
346
-		if ($mount->getInternalPath($absolutePath) === '') {
347
-			return $this->removeMount($mount, $absolutePath);
348
-		}
349
-		if ($this->is_dir($path)) {
350
-			$result = $this->basicOperation('rmdir', $path, array('delete'));
351
-		} else {
352
-			$result = false;
353
-		}
354
-
355
-		if (!$result && !$this->file_exists($path)) { //clear ghost files from the cache on delete
356
-			$storage = $mount->getStorage();
357
-			$internalPath = $mount->getInternalPath($absolutePath);
358
-			$storage->getUpdater()->remove($internalPath);
359
-		}
360
-		return $result;
361
-	}
362
-
363
-	/**
364
-	 * @param string $path
365
-	 * @return resource
366
-	 */
367
-	public function opendir($path) {
368
-		return $this->basicOperation('opendir', $path, array('read'));
369
-	}
370
-
371
-	/**
372
-	 * @param $handle
373
-	 * @return mixed
374
-	 */
375
-	public function readdir($handle) {
376
-		$fsLocal = new Storage\Local(array('datadir' => '/'));
377
-		return $fsLocal->readdir($handle);
378
-	}
379
-
380
-	/**
381
-	 * @param string $path
382
-	 * @return bool|mixed
383
-	 */
384
-	public function is_dir($path) {
385
-		if ($path == '/') {
386
-			return true;
387
-		}
388
-		return $this->basicOperation('is_dir', $path);
389
-	}
390
-
391
-	/**
392
-	 * @param string $path
393
-	 * @return bool|mixed
394
-	 */
395
-	public function is_file($path) {
396
-		if ($path == '/') {
397
-			return false;
398
-		}
399
-		return $this->basicOperation('is_file', $path);
400
-	}
401
-
402
-	/**
403
-	 * @param string $path
404
-	 * @return mixed
405
-	 */
406
-	public function stat($path) {
407
-		return $this->basicOperation('stat', $path);
408
-	}
409
-
410
-	/**
411
-	 * @param string $path
412
-	 * @return mixed
413
-	 */
414
-	public function filetype($path) {
415
-		return $this->basicOperation('filetype', $path);
416
-	}
417
-
418
-	/**
419
-	 * @param string $path
420
-	 * @return mixed
421
-	 */
422
-	public function filesize($path) {
423
-		return $this->basicOperation('filesize', $path);
424
-	}
425
-
426
-	/**
427
-	 * @param string $path
428
-	 * @return bool|mixed
429
-	 * @throws \OCP\Files\InvalidPathException
430
-	 */
431
-	public function readfile($path) {
432
-		$this->assertPathLength($path);
433
-		@ob_end_clean();
434
-		$handle = $this->fopen($path, 'rb');
435
-		if ($handle) {
436
-			$chunkSize = 8192; // 8 kB chunks
437
-			while (!feof($handle)) {
438
-				echo fread($handle, $chunkSize);
439
-				flush();
440
-			}
441
-			fclose($handle);
442
-			$size = $this->filesize($path);
443
-			return $size;
444
-		}
445
-		return false;
446
-	}
447
-
448
-	/**
449
-	 * @param string $path
450
-	 * @param int $from
451
-	 * @param int $to
452
-	 * @return bool|mixed
453
-	 * @throws \OCP\Files\InvalidPathException
454
-	 * @throws \OCP\Files\UnseekableException
455
-	 */
456
-	public function readfilePart($path, $from, $to) {
457
-		$this->assertPathLength($path);
458
-		@ob_end_clean();
459
-		$handle = $this->fopen($path, 'rb');
460
-		if ($handle) {
461
-			if (fseek($handle, $from) === 0) {
462
-				$chunkSize = 8192; // 8 kB chunks
463
-				$end = $to + 1;
464
-				while (!feof($handle) && ftell($handle) < $end) {
465
-					$len = $end - ftell($handle);
466
-					if ($len > $chunkSize) {
467
-						$len = $chunkSize;
468
-					}
469
-					echo fread($handle, $len);
470
-					flush();
471
-				}
472
-				$size = ftell($handle) - $from;
473
-				return $size;
474
-			}
475
-
476
-			throw new \OCP\Files\UnseekableException('fseek error');
477
-		}
478
-		return false;
479
-	}
480
-
481
-	/**
482
-	 * @param string $path
483
-	 * @return mixed
484
-	 */
485
-	public function isCreatable($path) {
486
-		return $this->basicOperation('isCreatable', $path);
487
-	}
488
-
489
-	/**
490
-	 * @param string $path
491
-	 * @return mixed
492
-	 */
493
-	public function isReadable($path) {
494
-		return $this->basicOperation('isReadable', $path);
495
-	}
496
-
497
-	/**
498
-	 * @param string $path
499
-	 * @return mixed
500
-	 */
501
-	public function isUpdatable($path) {
502
-		return $this->basicOperation('isUpdatable', $path);
503
-	}
504
-
505
-	/**
506
-	 * @param string $path
507
-	 * @return bool|mixed
508
-	 */
509
-	public function isDeletable($path) {
510
-		$absolutePath = $this->getAbsolutePath($path);
511
-		$mount = Filesystem::getMountManager()->find($absolutePath);
512
-		if ($mount->getInternalPath($absolutePath) === '') {
513
-			return $mount instanceof MoveableMount;
514
-		}
515
-		return $this->basicOperation('isDeletable', $path);
516
-	}
517
-
518
-	/**
519
-	 * @param string $path
520
-	 * @return mixed
521
-	 */
522
-	public function isSharable($path) {
523
-		return $this->basicOperation('isSharable', $path);
524
-	}
525
-
526
-	/**
527
-	 * @param string $path
528
-	 * @return bool|mixed
529
-	 */
530
-	public function file_exists($path) {
531
-		if ($path == '/') {
532
-			return true;
533
-		}
534
-		return $this->basicOperation('file_exists', $path);
535
-	}
536
-
537
-	/**
538
-	 * @param string $path
539
-	 * @return mixed
540
-	 */
541
-	public function filemtime($path) {
542
-		return $this->basicOperation('filemtime', $path);
543
-	}
544
-
545
-	/**
546
-	 * @param string $path
547
-	 * @param int|string $mtime
548
-	 * @return bool
549
-	 */
550
-	public function touch($path, $mtime = null) {
551
-		if (!is_null($mtime) and !is_numeric($mtime)) {
552
-			$mtime = strtotime($mtime);
553
-		}
554
-
555
-		$hooks = array('touch');
556
-
557
-		if (!$this->file_exists($path)) {
558
-			$hooks[] = 'create';
559
-			$hooks[] = 'write';
560
-		}
561
-		$result = $this->basicOperation('touch', $path, $hooks, $mtime);
562
-		if (!$result) {
563
-			// If create file fails because of permissions on external storage like SMB folders,
564
-			// check file exists and return false if not.
565
-			if (!$this->file_exists($path)) {
566
-				return false;
567
-			}
568
-			if (is_null($mtime)) {
569
-				$mtime = time();
570
-			}
571
-			//if native touch fails, we emulate it by changing the mtime in the cache
572
-			$this->putFileInfo($path, array('mtime' => floor($mtime)));
573
-		}
574
-		return true;
575
-	}
576
-
577
-	/**
578
-	 * @param string $path
579
-	 * @return mixed
580
-	 */
581
-	public function file_get_contents($path) {
582
-		return $this->basicOperation('file_get_contents', $path, array('read'));
583
-	}
584
-
585
-	/**
586
-	 * @param bool $exists
587
-	 * @param string $path
588
-	 * @param bool $run
589
-	 */
590
-	protected function emit_file_hooks_pre($exists, $path, &$run) {
591
-		if (!$exists) {
592
-			\OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_create, array(
593
-				Filesystem::signal_param_path => $this->getHookPath($path),
594
-				Filesystem::signal_param_run => &$run,
595
-			));
596
-		} else {
597
-			\OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_update, array(
598
-				Filesystem::signal_param_path => $this->getHookPath($path),
599
-				Filesystem::signal_param_run => &$run,
600
-			));
601
-		}
602
-		\OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_write, array(
603
-			Filesystem::signal_param_path => $this->getHookPath($path),
604
-			Filesystem::signal_param_run => &$run,
605
-		));
606
-	}
607
-
608
-	/**
609
-	 * @param bool $exists
610
-	 * @param string $path
611
-	 */
612
-	protected function emit_file_hooks_post($exists, $path) {
613
-		if (!$exists) {
614
-			\OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_post_create, array(
615
-				Filesystem::signal_param_path => $this->getHookPath($path),
616
-			));
617
-		} else {
618
-			\OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_post_update, array(
619
-				Filesystem::signal_param_path => $this->getHookPath($path),
620
-			));
621
-		}
622
-		\OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_post_write, array(
623
-			Filesystem::signal_param_path => $this->getHookPath($path),
624
-		));
625
-	}
626
-
627
-	/**
628
-	 * @param string $path
629
-	 * @param mixed $data
630
-	 * @return bool|mixed
631
-	 * @throws \Exception
632
-	 */
633
-	public function file_put_contents($path, $data) {
634
-		if (is_resource($data)) { //not having to deal with streams in file_put_contents makes life easier
635
-			$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
636
-			if (Filesystem::isValidPath($path)
637
-				and !Filesystem::isFileBlacklisted($path)
638
-			) {
639
-				$path = $this->getRelativePath($absolutePath);
640
-
641
-				$this->lockFile($path, ILockingProvider::LOCK_SHARED);
642
-
643
-				$exists = $this->file_exists($path);
644
-				$run = true;
645
-				if ($this->shouldEmitHooks($path)) {
646
-					$this->emit_file_hooks_pre($exists, $path, $run);
647
-				}
648
-				if (!$run) {
649
-					$this->unlockFile($path, ILockingProvider::LOCK_SHARED);
650
-					return false;
651
-				}
652
-
653
-				$this->changeLock($path, ILockingProvider::LOCK_EXCLUSIVE);
654
-
655
-				/** @var \OC\Files\Storage\Storage $storage */
656
-				list($storage, $internalPath) = $this->resolvePath($path);
657
-				$target = $storage->fopen($internalPath, 'w');
658
-				if ($target) {
659
-					list (, $result) = \OC_Helper::streamCopy($data, $target);
660
-					fclose($target);
661
-					fclose($data);
662
-
663
-					$this->writeUpdate($storage, $internalPath);
664
-
665
-					$this->changeLock($path, ILockingProvider::LOCK_SHARED);
666
-
667
-					if ($this->shouldEmitHooks($path) && $result !== false) {
668
-						$this->emit_file_hooks_post($exists, $path);
669
-					}
670
-					$this->unlockFile($path, ILockingProvider::LOCK_SHARED);
671
-					return $result;
672
-				} else {
673
-					$this->unlockFile($path, ILockingProvider::LOCK_EXCLUSIVE);
674
-					return false;
675
-				}
676
-			} else {
677
-				return false;
678
-			}
679
-		} else {
680
-			$hooks = ($this->file_exists($path)) ? array('update', 'write') : array('create', 'write');
681
-			return $this->basicOperation('file_put_contents', $path, $hooks, $data);
682
-		}
683
-	}
684
-
685
-	/**
686
-	 * @param string $path
687
-	 * @return bool|mixed
688
-	 */
689
-	public function unlink($path) {
690
-		if ($path === '' || $path === '/') {
691
-			// do not allow deleting the root
692
-			return false;
693
-		}
694
-		$postFix = (substr($path, -1, 1) === '/') ? '/' : '';
695
-		$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
696
-		$mount = Filesystem::getMountManager()->find($absolutePath . $postFix);
697
-		if ($mount and $mount->getInternalPath($absolutePath) === '') {
698
-			return $this->removeMount($mount, $absolutePath);
699
-		}
700
-		if ($this->is_dir($path)) {
701
-			$result = $this->basicOperation('rmdir', $path, ['delete']);
702
-		} else {
703
-			$result = $this->basicOperation('unlink', $path, ['delete']);
704
-		}
705
-		if (!$result && !$this->file_exists($path)) { //clear ghost files from the cache on delete
706
-			$storage = $mount->getStorage();
707
-			$internalPath = $mount->getInternalPath($absolutePath);
708
-			$storage->getUpdater()->remove($internalPath);
709
-			return true;
710
-		} else {
711
-			return $result;
712
-		}
713
-	}
714
-
715
-	/**
716
-	 * @param string $directory
717
-	 * @return bool|mixed
718
-	 */
719
-	public function deleteAll($directory) {
720
-		return $this->rmdir($directory);
721
-	}
722
-
723
-	/**
724
-	 * Rename/move a file or folder from the source path to target path.
725
-	 *
726
-	 * @param string $path1 source path
727
-	 * @param string $path2 target path
728
-	 *
729
-	 * @return bool|mixed
730
-	 */
731
-	public function rename($path1, $path2) {
732
-		$absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1));
733
-		$absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($path2));
734
-		$result = false;
735
-		if (
736
-			Filesystem::isValidPath($path2)
737
-			and Filesystem::isValidPath($path1)
738
-			and !Filesystem::isFileBlacklisted($path2)
739
-		) {
740
-			$path1 = $this->getRelativePath($absolutePath1);
741
-			$path2 = $this->getRelativePath($absolutePath2);
742
-			$exists = $this->file_exists($path2);
743
-
744
-			if ($path1 == null or $path2 == null) {
745
-				return false;
746
-			}
747
-
748
-			$this->lockFile($path1, ILockingProvider::LOCK_SHARED, true);
749
-			try {
750
-				$this->lockFile($path2, ILockingProvider::LOCK_SHARED, true);
751
-			} catch (LockedException $e) {
752
-				$this->unlockFile($path1, ILockingProvider::LOCK_SHARED);
753
-				throw $e;
754
-			}
755
-
756
-			$run = true;
757
-			if ($this->shouldEmitHooks($path1) && (Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2))) {
758
-				// if it was a rename from a part file to a regular file it was a write and not a rename operation
759
-				$this->emit_file_hooks_pre($exists, $path2, $run);
760
-			} elseif ($this->shouldEmitHooks($path1)) {
761
-				\OC_Hook::emit(
762
-					Filesystem::CLASSNAME, Filesystem::signal_rename,
763
-					array(
764
-						Filesystem::signal_param_oldpath => $this->getHookPath($path1),
765
-						Filesystem::signal_param_newpath => $this->getHookPath($path2),
766
-						Filesystem::signal_param_run => &$run
767
-					)
768
-				);
769
-			}
770
-			if ($run) {
771
-				$this->verifyPath(dirname($path2), basename($path2));
772
-
773
-				$manager = Filesystem::getMountManager();
774
-				$mount1 = $this->getMount($path1);
775
-				$mount2 = $this->getMount($path2);
776
-				$storage1 = $mount1->getStorage();
777
-				$storage2 = $mount2->getStorage();
778
-				$internalPath1 = $mount1->getInternalPath($absolutePath1);
779
-				$internalPath2 = $mount2->getInternalPath($absolutePath2);
780
-
781
-				$this->changeLock($path1, ILockingProvider::LOCK_EXCLUSIVE, true);
782
-				$this->changeLock($path2, ILockingProvider::LOCK_EXCLUSIVE, true);
783
-
784
-				if ($internalPath1 === '' and $mount1 instanceof MoveableMount) {
785
-					if ($this->isTargetAllowed($absolutePath2)) {
786
-						/**
787
-						 * @var \OC\Files\Mount\MountPoint | \OC\Files\Mount\MoveableMount $mount1
788
-						 */
789
-						$sourceMountPoint = $mount1->getMountPoint();
790
-						$result = $mount1->moveMount($absolutePath2);
791
-						$manager->moveMount($sourceMountPoint, $mount1->getMountPoint());
792
-					} else {
793
-						$result = false;
794
-					}
795
-					// moving a file/folder within the same mount point
796
-				} elseif ($storage1 === $storage2) {
797
-					if ($storage1) {
798
-						$result = $storage1->rename($internalPath1, $internalPath2);
799
-					} else {
800
-						$result = false;
801
-					}
802
-					// moving a file/folder between storages (from $storage1 to $storage2)
803
-				} else {
804
-					$result = $storage2->moveFromStorage($storage1, $internalPath1, $internalPath2);
805
-				}
806
-
807
-				if ((Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2)) && $result !== false) {
808
-					// if it was a rename from a part file to a regular file it was a write and not a rename operation
809
-
810
-					$this->writeUpdate($storage2, $internalPath2);
811
-				} else if ($result) {
812
-					if ($internalPath1 !== '') { // don't do a cache update for moved mounts
813
-						$this->renameUpdate($storage1, $storage2, $internalPath1, $internalPath2);
814
-					}
815
-				}
816
-
817
-				$this->changeLock($path1, ILockingProvider::LOCK_SHARED, true);
818
-				$this->changeLock($path2, ILockingProvider::LOCK_SHARED, true);
819
-
820
-				if ((Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2)) && $result !== false) {
821
-					if ($this->shouldEmitHooks()) {
822
-						$this->emit_file_hooks_post($exists, $path2);
823
-					}
824
-				} elseif ($result) {
825
-					if ($this->shouldEmitHooks($path1) and $this->shouldEmitHooks($path2)) {
826
-						\OC_Hook::emit(
827
-							Filesystem::CLASSNAME,
828
-							Filesystem::signal_post_rename,
829
-							array(
830
-								Filesystem::signal_param_oldpath => $this->getHookPath($path1),
831
-								Filesystem::signal_param_newpath => $this->getHookPath($path2)
832
-							)
833
-						);
834
-					}
835
-				}
836
-			}
837
-			$this->unlockFile($path1, ILockingProvider::LOCK_SHARED, true);
838
-			$this->unlockFile($path2, ILockingProvider::LOCK_SHARED, true);
839
-		}
840
-		return $result;
841
-	}
842
-
843
-	/**
844
-	 * Copy a file/folder from the source path to target path
845
-	 *
846
-	 * @param string $path1 source path
847
-	 * @param string $path2 target path
848
-	 * @param bool $preserveMtime whether to preserve mtime on the copy
849
-	 *
850
-	 * @return bool|mixed
851
-	 */
852
-	public function copy($path1, $path2, $preserveMtime = false) {
853
-		$absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1));
854
-		$absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($path2));
855
-		$result = false;
856
-		if (
857
-			Filesystem::isValidPath($path2)
858
-			and Filesystem::isValidPath($path1)
859
-			and !Filesystem::isFileBlacklisted($path2)
860
-		) {
861
-			$path1 = $this->getRelativePath($absolutePath1);
862
-			$path2 = $this->getRelativePath($absolutePath2);
863
-
864
-			if ($path1 == null or $path2 == null) {
865
-				return false;
866
-			}
867
-			$run = true;
868
-
869
-			$this->lockFile($path2, ILockingProvider::LOCK_SHARED);
870
-			$this->lockFile($path1, ILockingProvider::LOCK_SHARED);
871
-			$lockTypePath1 = ILockingProvider::LOCK_SHARED;
872
-			$lockTypePath2 = ILockingProvider::LOCK_SHARED;
873
-
874
-			try {
875
-
876
-				$exists = $this->file_exists($path2);
877
-				if ($this->shouldEmitHooks()) {
878
-					\OC_Hook::emit(
879
-						Filesystem::CLASSNAME,
880
-						Filesystem::signal_copy,
881
-						array(
882
-							Filesystem::signal_param_oldpath => $this->getHookPath($path1),
883
-							Filesystem::signal_param_newpath => $this->getHookPath($path2),
884
-							Filesystem::signal_param_run => &$run
885
-						)
886
-					);
887
-					$this->emit_file_hooks_pre($exists, $path2, $run);
888
-				}
889
-				if ($run) {
890
-					$mount1 = $this->getMount($path1);
891
-					$mount2 = $this->getMount($path2);
892
-					$storage1 = $mount1->getStorage();
893
-					$internalPath1 = $mount1->getInternalPath($absolutePath1);
894
-					$storage2 = $mount2->getStorage();
895
-					$internalPath2 = $mount2->getInternalPath($absolutePath2);
896
-
897
-					$this->changeLock($path2, ILockingProvider::LOCK_EXCLUSIVE);
898
-					$lockTypePath2 = ILockingProvider::LOCK_EXCLUSIVE;
899
-
900
-					if ($mount1->getMountPoint() == $mount2->getMountPoint()) {
901
-						if ($storage1) {
902
-							$result = $storage1->copy($internalPath1, $internalPath2);
903
-						} else {
904
-							$result = false;
905
-						}
906
-					} else {
907
-						$result = $storage2->copyFromStorage($storage1, $internalPath1, $internalPath2);
908
-					}
909
-
910
-					$this->writeUpdate($storage2, $internalPath2);
911
-
912
-					$this->changeLock($path2, ILockingProvider::LOCK_SHARED);
913
-					$lockTypePath2 = ILockingProvider::LOCK_SHARED;
914
-
915
-					if ($this->shouldEmitHooks() && $result !== false) {
916
-						\OC_Hook::emit(
917
-							Filesystem::CLASSNAME,
918
-							Filesystem::signal_post_copy,
919
-							array(
920
-								Filesystem::signal_param_oldpath => $this->getHookPath($path1),
921
-								Filesystem::signal_param_newpath => $this->getHookPath($path2)
922
-							)
923
-						);
924
-						$this->emit_file_hooks_post($exists, $path2);
925
-					}
926
-
927
-				}
928
-			} catch (\Exception $e) {
929
-				$this->unlockFile($path2, $lockTypePath2);
930
-				$this->unlockFile($path1, $lockTypePath1);
931
-				throw $e;
932
-			}
933
-
934
-			$this->unlockFile($path2, $lockTypePath2);
935
-			$this->unlockFile($path1, $lockTypePath1);
936
-
937
-		}
938
-		return $result;
939
-	}
940
-
941
-	/**
942
-	 * @param string $path
943
-	 * @param string $mode 'r' or 'w'
944
-	 * @return resource
945
-	 */
946
-	public function fopen($path, $mode) {
947
-		$mode = str_replace('b', '', $mode); // the binary flag is a windows only feature which we do not support
948
-		$hooks = array();
949
-		switch ($mode) {
950
-			case 'r':
951
-				$hooks[] = 'read';
952
-				break;
953
-			case 'r+':
954
-			case 'w+':
955
-			case 'x+':
956
-			case 'a+':
957
-				$hooks[] = 'read';
958
-				$hooks[] = 'write';
959
-				break;
960
-			case 'w':
961
-			case 'x':
962
-			case 'a':
963
-				$hooks[] = 'write';
964
-				break;
965
-			default:
966
-				\OCP\Util::writeLog('core', 'invalid mode (' . $mode . ') for ' . $path, \OCP\Util::ERROR);
967
-		}
968
-
969
-		if ($mode !== 'r' && $mode !== 'w') {
970
-			\OC::$server->getLogger()->info('Trying to open a file with a mode other than "r" or "w" can cause severe performance issues with some backends');
971
-		}
972
-
973
-		return $this->basicOperation('fopen', $path, $hooks, $mode);
974
-	}
975
-
976
-	/**
977
-	 * @param string $path
978
-	 * @return bool|string
979
-	 * @throws \OCP\Files\InvalidPathException
980
-	 */
981
-	public function toTmpFile($path) {
982
-		$this->assertPathLength($path);
983
-		if (Filesystem::isValidPath($path)) {
984
-			$source = $this->fopen($path, 'r');
985
-			if ($source) {
986
-				$extension = pathinfo($path, PATHINFO_EXTENSION);
987
-				$tmpFile = \OC::$server->getTempManager()->getTemporaryFile($extension);
988
-				file_put_contents($tmpFile, $source);
989
-				return $tmpFile;
990
-			} else {
991
-				return false;
992
-			}
993
-		} else {
994
-			return false;
995
-		}
996
-	}
997
-
998
-	/**
999
-	 * @param string $tmpFile
1000
-	 * @param string $path
1001
-	 * @return bool|mixed
1002
-	 * @throws \OCP\Files\InvalidPathException
1003
-	 */
1004
-	public function fromTmpFile($tmpFile, $path) {
1005
-		$this->assertPathLength($path);
1006
-		if (Filesystem::isValidPath($path)) {
1007
-
1008
-			// Get directory that the file is going into
1009
-			$filePath = dirname($path);
1010
-
1011
-			// Create the directories if any
1012
-			if (!$this->file_exists($filePath)) {
1013
-				$result = $this->createParentDirectories($filePath);
1014
-				if ($result === false) {
1015
-					return false;
1016
-				}
1017
-			}
1018
-
1019
-			$source = fopen($tmpFile, 'r');
1020
-			if ($source) {
1021
-				$result = $this->file_put_contents($path, $source);
1022
-				// $this->file_put_contents() might have already closed
1023
-				// the resource, so we check it, before trying to close it
1024
-				// to avoid messages in the error log.
1025
-				if (is_resource($source)) {
1026
-					fclose($source);
1027
-				}
1028
-				unlink($tmpFile);
1029
-				return $result;
1030
-			} else {
1031
-				return false;
1032
-			}
1033
-		} else {
1034
-			return false;
1035
-		}
1036
-	}
1037
-
1038
-
1039
-	/**
1040
-	 * @param string $path
1041
-	 * @return mixed
1042
-	 * @throws \OCP\Files\InvalidPathException
1043
-	 */
1044
-	public function getMimeType($path) {
1045
-		$this->assertPathLength($path);
1046
-		return $this->basicOperation('getMimeType', $path);
1047
-	}
1048
-
1049
-	/**
1050
-	 * @param string $type
1051
-	 * @param string $path
1052
-	 * @param bool $raw
1053
-	 * @return bool|null|string
1054
-	 */
1055
-	public function hash($type, $path, $raw = false) {
1056
-		$postFix = (substr($path, -1, 1) === '/') ? '/' : '';
1057
-		$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
1058
-		if (Filesystem::isValidPath($path)) {
1059
-			$path = $this->getRelativePath($absolutePath);
1060
-			if ($path == null) {
1061
-				return false;
1062
-			}
1063
-			if ($this->shouldEmitHooks($path)) {
1064
-				\OC_Hook::emit(
1065
-					Filesystem::CLASSNAME,
1066
-					Filesystem::signal_read,
1067
-					array(Filesystem::signal_param_path => $this->getHookPath($path))
1068
-				);
1069
-			}
1070
-			list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix);
1071
-			if ($storage) {
1072
-				$result = $storage->hash($type, $internalPath, $raw);
1073
-				return $result;
1074
-			}
1075
-		}
1076
-		return null;
1077
-	}
1078
-
1079
-	/**
1080
-	 * @param string $path
1081
-	 * @return mixed
1082
-	 * @throws \OCP\Files\InvalidPathException
1083
-	 */
1084
-	public function free_space($path = '/') {
1085
-		$this->assertPathLength($path);
1086
-		return $this->basicOperation('free_space', $path);
1087
-	}
1088
-
1089
-	/**
1090
-	 * abstraction layer for basic filesystem functions: wrapper for \OC\Files\Storage\Storage
1091
-	 *
1092
-	 * @param string $operation
1093
-	 * @param string $path
1094
-	 * @param array $hooks (optional)
1095
-	 * @param mixed $extraParam (optional)
1096
-	 * @return mixed
1097
-	 * @throws \Exception
1098
-	 *
1099
-	 * This method takes requests for basic filesystem functions (e.g. reading & writing
1100
-	 * files), processes hooks and proxies, sanitises paths, and finally passes them on to
1101
-	 * \OC\Files\Storage\Storage for delegation to a storage backend for execution
1102
-	 */
1103
-	private function basicOperation($operation, $path, $hooks = [], $extraParam = null) {
1104
-		$postFix = (substr($path, -1, 1) === '/') ? '/' : '';
1105
-		$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
1106
-		if (Filesystem::isValidPath($path)
1107
-			and !Filesystem::isFileBlacklisted($path)
1108
-		) {
1109
-			$path = $this->getRelativePath($absolutePath);
1110
-			if ($path == null) {
1111
-				return false;
1112
-			}
1113
-
1114
-			if (in_array('write', $hooks) || in_array('delete', $hooks) || in_array('read', $hooks)) {
1115
-				// always a shared lock during pre-hooks so the hook can read the file
1116
-				$this->lockFile($path, ILockingProvider::LOCK_SHARED);
1117
-			}
1118
-
1119
-			$run = $this->runHooks($hooks, $path);
1120
-			/** @var \OC\Files\Storage\Storage $storage */
1121
-			list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix);
1122
-			if ($run and $storage) {
1123
-				if (in_array('write', $hooks) || in_array('delete', $hooks)) {
1124
-					$this->changeLock($path, ILockingProvider::LOCK_EXCLUSIVE);
1125
-				}
1126
-				try {
1127
-					if (!is_null($extraParam)) {
1128
-						$result = $storage->$operation($internalPath, $extraParam);
1129
-					} else {
1130
-						$result = $storage->$operation($internalPath);
1131
-					}
1132
-				} catch (\Exception $e) {
1133
-					if (in_array('write', $hooks) || in_array('delete', $hooks)) {
1134
-						$this->unlockFile($path, ILockingProvider::LOCK_EXCLUSIVE);
1135
-					} else if (in_array('read', $hooks)) {
1136
-						$this->unlockFile($path, ILockingProvider::LOCK_SHARED);
1137
-					}
1138
-					throw $e;
1139
-				}
1140
-
1141
-				if ($result && in_array('delete', $hooks) and $result) {
1142
-					$this->removeUpdate($storage, $internalPath);
1143
-				}
1144
-				if ($result && in_array('write', $hooks) and $operation !== 'fopen') {
1145
-					$this->writeUpdate($storage, $internalPath);
1146
-				}
1147
-				if ($result && in_array('touch', $hooks)) {
1148
-					$this->writeUpdate($storage, $internalPath, $extraParam);
1149
-				}
1150
-
1151
-				if ((in_array('write', $hooks) || in_array('delete', $hooks)) && ($operation !== 'fopen' || $result === false)) {
1152
-					$this->changeLock($path, ILockingProvider::LOCK_SHARED);
1153
-				}
1154
-
1155
-				$unlockLater = false;
1156
-				if ($this->lockingEnabled && $operation === 'fopen' && is_resource($result)) {
1157
-					$unlockLater = true;
1158
-					// make sure our unlocking callback will still be called if connection is aborted
1159
-					ignore_user_abort(true);
1160
-					$result = CallbackWrapper::wrap($result, null, null, function () use ($hooks, $path) {
1161
-						if (in_array('write', $hooks)) {
1162
-							$this->unlockFile($path, ILockingProvider::LOCK_EXCLUSIVE);
1163
-						} else if (in_array('read', $hooks)) {
1164
-							$this->unlockFile($path, ILockingProvider::LOCK_SHARED);
1165
-						}
1166
-					});
1167
-				}
1168
-
1169
-				if ($this->shouldEmitHooks($path) && $result !== false) {
1170
-					if ($operation != 'fopen') { //no post hooks for fopen, the file stream is still open
1171
-						$this->runHooks($hooks, $path, true);
1172
-					}
1173
-				}
1174
-
1175
-				if (!$unlockLater
1176
-					&& (in_array('write', $hooks) || in_array('delete', $hooks) || in_array('read', $hooks))
1177
-				) {
1178
-					$this->unlockFile($path, ILockingProvider::LOCK_SHARED);
1179
-				}
1180
-				return $result;
1181
-			} else {
1182
-				$this->unlockFile($path, ILockingProvider::LOCK_SHARED);
1183
-			}
1184
-		}
1185
-		return null;
1186
-	}
1187
-
1188
-	/**
1189
-	 * get the path relative to the default root for hook usage
1190
-	 *
1191
-	 * @param string $path
1192
-	 * @return string
1193
-	 */
1194
-	private function getHookPath($path) {
1195
-		if (!Filesystem::getView()) {
1196
-			return $path;
1197
-		}
1198
-		return Filesystem::getView()->getRelativePath($this->getAbsolutePath($path));
1199
-	}
1200
-
1201
-	private function shouldEmitHooks($path = '') {
1202
-		if ($path && Cache\Scanner::isPartialFile($path)) {
1203
-			return false;
1204
-		}
1205
-		if (!Filesystem::$loaded) {
1206
-			return false;
1207
-		}
1208
-		$defaultRoot = Filesystem::getRoot();
1209
-		if ($defaultRoot === null) {
1210
-			return false;
1211
-		}
1212
-		if ($this->fakeRoot === $defaultRoot) {
1213
-			return true;
1214
-		}
1215
-		$fullPath = $this->getAbsolutePath($path);
1216
-
1217
-		if ($fullPath === $defaultRoot) {
1218
-			return true;
1219
-		}
1220
-
1221
-		return (strlen($fullPath) > strlen($defaultRoot)) && (substr($fullPath, 0, strlen($defaultRoot) + 1) === $defaultRoot . '/');
1222
-	}
1223
-
1224
-	/**
1225
-	 * @param string[] $hooks
1226
-	 * @param string $path
1227
-	 * @param bool $post
1228
-	 * @return bool
1229
-	 */
1230
-	private function runHooks($hooks, $path, $post = false) {
1231
-		$relativePath = $path;
1232
-		$path = $this->getHookPath($path);
1233
-		$prefix = ($post) ? 'post_' : '';
1234
-		$run = true;
1235
-		if ($this->shouldEmitHooks($relativePath)) {
1236
-			foreach ($hooks as $hook) {
1237
-				if ($hook != 'read') {
1238
-					\OC_Hook::emit(
1239
-						Filesystem::CLASSNAME,
1240
-						$prefix . $hook,
1241
-						array(
1242
-							Filesystem::signal_param_run => &$run,
1243
-							Filesystem::signal_param_path => $path
1244
-						)
1245
-					);
1246
-				} elseif (!$post) {
1247
-					\OC_Hook::emit(
1248
-						Filesystem::CLASSNAME,
1249
-						$prefix . $hook,
1250
-						array(
1251
-							Filesystem::signal_param_path => $path
1252
-						)
1253
-					);
1254
-				}
1255
-			}
1256
-		}
1257
-		return $run;
1258
-	}
1259
-
1260
-	/**
1261
-	 * check if a file or folder has been updated since $time
1262
-	 *
1263
-	 * @param string $path
1264
-	 * @param int $time
1265
-	 * @return bool
1266
-	 */
1267
-	public function hasUpdated($path, $time) {
1268
-		return $this->basicOperation('hasUpdated', $path, array(), $time);
1269
-	}
1270
-
1271
-	/**
1272
-	 * @param string $ownerId
1273
-	 * @return \OC\User\User
1274
-	 */
1275
-	private function getUserObjectForOwner($ownerId) {
1276
-		$owner = $this->userManager->get($ownerId);
1277
-		if ($owner instanceof IUser) {
1278
-			return $owner;
1279
-		} else {
1280
-			return new User($ownerId, null);
1281
-		}
1282
-	}
1283
-
1284
-	/**
1285
-	 * Get file info from cache
1286
-	 *
1287
-	 * If the file is not in cached it will be scanned
1288
-	 * If the file has changed on storage the cache will be updated
1289
-	 *
1290
-	 * @param \OC\Files\Storage\Storage $storage
1291
-	 * @param string $internalPath
1292
-	 * @param string $relativePath
1293
-	 * @return array|bool
1294
-	 */
1295
-	private function getCacheEntry($storage, $internalPath, $relativePath) {
1296
-		$cache = $storage->getCache($internalPath);
1297
-		$data = $cache->get($internalPath);
1298
-		$watcher = $storage->getWatcher($internalPath);
1299
-
1300
-		try {
1301
-			// if the file is not in the cache or needs to be updated, trigger the scanner and reload the data
1302
-			if (!$data || $data['size'] === -1) {
1303
-				$this->lockFile($relativePath, ILockingProvider::LOCK_SHARED);
1304
-				if (!$storage->file_exists($internalPath)) {
1305
-					$this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED);
1306
-					return false;
1307
-				}
1308
-				$scanner = $storage->getScanner($internalPath);
1309
-				$scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
1310
-				$data = $cache->get($internalPath);
1311
-				$this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED);
1312
-			} else if (!Cache\Scanner::isPartialFile($internalPath) && $watcher->needsUpdate($internalPath, $data)) {
1313
-				$this->lockFile($relativePath, ILockingProvider::LOCK_SHARED);
1314
-				$watcher->update($internalPath, $data);
1315
-				$storage->getPropagator()->propagateChange($internalPath, time());
1316
-				$data = $cache->get($internalPath);
1317
-				$this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED);
1318
-			}
1319
-		} catch (LockedException $e) {
1320
-			// if the file is locked we just use the old cache info
1321
-		}
1322
-
1323
-		return $data;
1324
-	}
1325
-
1326
-	/**
1327
-	 * get the filesystem info
1328
-	 *
1329
-	 * @param string $path
1330
-	 * @param boolean|string $includeMountPoints true to add mountpoint sizes,
1331
-	 * 'ext' to add only ext storage mount point sizes. Defaults to true.
1332
-	 * defaults to true
1333
-	 * @return \OC\Files\FileInfo|false False if file does not exist
1334
-	 */
1335
-	public function getFileInfo($path, $includeMountPoints = true) {
1336
-		$this->assertPathLength($path);
1337
-		if (!Filesystem::isValidPath($path)) {
1338
-			return false;
1339
-		}
1340
-		if (Cache\Scanner::isPartialFile($path)) {
1341
-			return $this->getPartFileInfo($path);
1342
-		}
1343
-		$relativePath = $path;
1344
-		$path = Filesystem::normalizePath($this->fakeRoot . '/' . $path);
1345
-
1346
-		$mount = Filesystem::getMountManager()->find($path);
1347
-		$storage = $mount->getStorage();
1348
-		$internalPath = $mount->getInternalPath($path);
1349
-		if ($storage) {
1350
-			$data = $this->getCacheEntry($storage, $internalPath, $relativePath);
1351
-
1352
-			if (!$data instanceof ICacheEntry) {
1353
-				return false;
1354
-			}
1355
-
1356
-			if ($mount instanceof MoveableMount && $internalPath === '') {
1357
-				$data['permissions'] |= \OCP\Constants::PERMISSION_DELETE;
1358
-			}
1359
-
1360
-			$owner = $this->getUserObjectForOwner($storage->getOwner($internalPath));
1361
-			$info = new FileInfo($path, $storage, $internalPath, $data, $mount, $owner);
1362
-
1363
-			if ($data and isset($data['fileid'])) {
1364
-				if ($includeMountPoints and $data['mimetype'] === 'httpd/unix-directory') {
1365
-					//add the sizes of other mount points to the folder
1366
-					$extOnly = ($includeMountPoints === 'ext');
1367
-					$mounts = Filesystem::getMountManager()->findIn($path);
1368
-					$info->setSubMounts(array_filter($mounts, function (IMountPoint $mount) use ($extOnly) {
1369
-						$subStorage = $mount->getStorage();
1370
-						return !($extOnly && $subStorage instanceof \OCA\Files_Sharing\SharedStorage);
1371
-					}));
1372
-				}
1373
-			}
1374
-
1375
-			return $info;
1376
-		}
1377
-
1378
-		return false;
1379
-	}
1380
-
1381
-	/**
1382
-	 * get the content of a directory
1383
-	 *
1384
-	 * @param string $directory path under datadirectory
1385
-	 * @param string $mimetype_filter limit returned content to this mimetype or mimepart
1386
-	 * @return FileInfo[]
1387
-	 */
1388
-	public function getDirectoryContent($directory, $mimetype_filter = '') {
1389
-		$this->assertPathLength($directory);
1390
-		if (!Filesystem::isValidPath($directory)) {
1391
-			return [];
1392
-		}
1393
-		$path = $this->getAbsolutePath($directory);
1394
-		$path = Filesystem::normalizePath($path);
1395
-		$mount = $this->getMount($directory);
1396
-		$storage = $mount->getStorage();
1397
-		$internalPath = $mount->getInternalPath($path);
1398
-		if ($storage) {
1399
-			$cache = $storage->getCache($internalPath);
1400
-			$user = \OC_User::getUser();
1401
-
1402
-			$data = $this->getCacheEntry($storage, $internalPath, $directory);
1403
-
1404
-			if (!$data instanceof ICacheEntry || !isset($data['fileid']) || !($data->getPermissions() && Constants::PERMISSION_READ)) {
1405
-				return [];
1406
-			}
1407
-
1408
-			$folderId = $data['fileid'];
1409
-			$contents = $cache->getFolderContentsById($folderId); //TODO: mimetype_filter
1410
-
1411
-			$sharingDisabled = \OCP\Util::isSharingDisabledForUser();
1412
-			/**
1413
-			 * @var \OC\Files\FileInfo[] $files
1414
-			 */
1415
-			$files = array_map(function (ICacheEntry $content) use ($path, $storage, $mount, $sharingDisabled) {
1416
-				if ($sharingDisabled) {
1417
-					$content['permissions'] = $content['permissions'] & ~\OCP\Constants::PERMISSION_SHARE;
1418
-				}
1419
-				$owner = $this->getUserObjectForOwner($storage->getOwner($content['path']));
1420
-				return new FileInfo($path . '/' . $content['name'], $storage, $content['path'], $content, $mount, $owner);
1421
-			}, $contents);
1422
-
1423
-			//add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
1424
-			$mounts = Filesystem::getMountManager()->findIn($path);
1425
-			$dirLength = strlen($path);
1426
-			foreach ($mounts as $mount) {
1427
-				$mountPoint = $mount->getMountPoint();
1428
-				$subStorage = $mount->getStorage();
1429
-				if ($subStorage) {
1430
-					$subCache = $subStorage->getCache('');
1431
-
1432
-					$rootEntry = $subCache->get('');
1433
-					if (!$rootEntry) {
1434
-						$subScanner = $subStorage->getScanner('');
1435
-						try {
1436
-							$subScanner->scanFile('');
1437
-						} catch (\OCP\Files\StorageNotAvailableException $e) {
1438
-							continue;
1439
-						} catch (\OCP\Files\StorageInvalidException $e) {
1440
-							continue;
1441
-						} catch (\Exception $e) {
1442
-							// sometimes when the storage is not available it can be any exception
1443
-							\OCP\Util::writeLog(
1444
-								'core',
1445
-								'Exception while scanning storage "' . $subStorage->getId() . '": ' .
1446
-								get_class($e) . ': ' . $e->getMessage(),
1447
-								\OCP\Util::ERROR
1448
-							);
1449
-							continue;
1450
-						}
1451
-						$rootEntry = $subCache->get('');
1452
-					}
1453
-
1454
-					if ($rootEntry && ($rootEntry->getPermissions() && Constants::PERMISSION_READ)) {
1455
-						$relativePath = trim(substr($mountPoint, $dirLength), '/');
1456
-						if ($pos = strpos($relativePath, '/')) {
1457
-							//mountpoint inside subfolder add size to the correct folder
1458
-							$entryName = substr($relativePath, 0, $pos);
1459
-							foreach ($files as &$entry) {
1460
-								if ($entry->getName() === $entryName) {
1461
-									$entry->addSubEntry($rootEntry, $mountPoint);
1462
-								}
1463
-							}
1464
-						} else { //mountpoint in this folder, add an entry for it
1465
-							$rootEntry['name'] = $relativePath;
1466
-							$rootEntry['type'] = $rootEntry['mimetype'] === 'httpd/unix-directory' ? 'dir' : 'file';
1467
-							$permissions = $rootEntry['permissions'];
1468
-							// do not allow renaming/deleting the mount point if they are not shared files/folders
1469
-							// for shared files/folders we use the permissions given by the owner
1470
-							if ($mount instanceof MoveableMount) {
1471
-								$rootEntry['permissions'] = $permissions | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE;
1472
-							} else {
1473
-								$rootEntry['permissions'] = $permissions & (\OCP\Constants::PERMISSION_ALL - (\OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE));
1474
-							}
1475
-
1476
-							//remove any existing entry with the same name
1477
-							foreach ($files as $i => $file) {
1478
-								if ($file['name'] === $rootEntry['name']) {
1479
-									unset($files[$i]);
1480
-									break;
1481
-								}
1482
-							}
1483
-							$rootEntry['path'] = substr(Filesystem::normalizePath($path . '/' . $rootEntry['name']), strlen($user) + 2); // full path without /$user/
1484
-
1485
-							// if sharing was disabled for the user we remove the share permissions
1486
-							if (\OCP\Util::isSharingDisabledForUser()) {
1487
-								$rootEntry['permissions'] = $rootEntry['permissions'] & ~\OCP\Constants::PERMISSION_SHARE;
1488
-							}
1489
-
1490
-							$owner = $this->getUserObjectForOwner($subStorage->getOwner(''));
1491
-							$files[] = new FileInfo($path . '/' . $rootEntry['name'], $subStorage, '', $rootEntry, $mount, $owner);
1492
-						}
1493
-					}
1494
-				}
1495
-			}
1496
-
1497
-			if ($mimetype_filter) {
1498
-				$files = array_filter($files, function (FileInfo $file) use ($mimetype_filter) {
1499
-					if (strpos($mimetype_filter, '/')) {
1500
-						return $file->getMimetype() === $mimetype_filter;
1501
-					} else {
1502
-						return $file->getMimePart() === $mimetype_filter;
1503
-					}
1504
-				});
1505
-			}
1506
-
1507
-			return $files;
1508
-		} else {
1509
-			return [];
1510
-		}
1511
-	}
1512
-
1513
-	/**
1514
-	 * change file metadata
1515
-	 *
1516
-	 * @param string $path
1517
-	 * @param array|\OCP\Files\FileInfo $data
1518
-	 * @return int
1519
-	 *
1520
-	 * returns the fileid of the updated file
1521
-	 */
1522
-	public function putFileInfo($path, $data) {
1523
-		$this->assertPathLength($path);
1524
-		if ($data instanceof FileInfo) {
1525
-			$data = $data->getData();
1526
-		}
1527
-		$path = Filesystem::normalizePath($this->fakeRoot . '/' . $path);
1528
-		/**
1529
-		 * @var \OC\Files\Storage\Storage $storage
1530
-		 * @var string $internalPath
1531
-		 */
1532
-		list($storage, $internalPath) = Filesystem::resolvePath($path);
1533
-		if ($storage) {
1534
-			$cache = $storage->getCache($path);
1535
-
1536
-			if (!$cache->inCache($internalPath)) {
1537
-				$scanner = $storage->getScanner($internalPath);
1538
-				$scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
1539
-			}
1540
-
1541
-			return $cache->put($internalPath, $data);
1542
-		} else {
1543
-			return -1;
1544
-		}
1545
-	}
1546
-
1547
-	/**
1548
-	 * search for files with the name matching $query
1549
-	 *
1550
-	 * @param string $query
1551
-	 * @return FileInfo[]
1552
-	 */
1553
-	public function search($query) {
1554
-		return $this->searchCommon('search', array('%' . $query . '%'));
1555
-	}
1556
-
1557
-	/**
1558
-	 * search for files with the name matching $query
1559
-	 *
1560
-	 * @param string $query
1561
-	 * @return FileInfo[]
1562
-	 */
1563
-	public function searchRaw($query) {
1564
-		return $this->searchCommon('search', array($query));
1565
-	}
1566
-
1567
-	/**
1568
-	 * search for files by mimetype
1569
-	 *
1570
-	 * @param string $mimetype
1571
-	 * @return FileInfo[]
1572
-	 */
1573
-	public function searchByMime($mimetype) {
1574
-		return $this->searchCommon('searchByMime', array($mimetype));
1575
-	}
1576
-
1577
-	/**
1578
-	 * search for files by tag
1579
-	 *
1580
-	 * @param string|int $tag name or tag id
1581
-	 * @param string $userId owner of the tags
1582
-	 * @return FileInfo[]
1583
-	 */
1584
-	public function searchByTag($tag, $userId) {
1585
-		return $this->searchCommon('searchByTag', array($tag, $userId));
1586
-	}
1587
-
1588
-	/**
1589
-	 * @param string $method cache method
1590
-	 * @param array $args
1591
-	 * @return FileInfo[]
1592
-	 */
1593
-	private function searchCommon($method, $args) {
1594
-		$files = array();
1595
-		$rootLength = strlen($this->fakeRoot);
1596
-
1597
-		$mount = $this->getMount('');
1598
-		$mountPoint = $mount->getMountPoint();
1599
-		$storage = $mount->getStorage();
1600
-		if ($storage) {
1601
-			$cache = $storage->getCache('');
1602
-
1603
-			$results = call_user_func_array(array($cache, $method), $args);
1604
-			foreach ($results as $result) {
1605
-				if (substr($mountPoint . $result['path'], 0, $rootLength + 1) === $this->fakeRoot . '/') {
1606
-					$internalPath = $result['path'];
1607
-					$path = $mountPoint . $result['path'];
1608
-					$result['path'] = substr($mountPoint . $result['path'], $rootLength);
1609
-					$owner = \OC::$server->getUserManager()->get($storage->getOwner($internalPath));
1610
-					$files[] = new FileInfo($path, $storage, $internalPath, $result, $mount, $owner);
1611
-				}
1612
-			}
1613
-
1614
-			$mounts = Filesystem::getMountManager()->findIn($this->fakeRoot);
1615
-			foreach ($mounts as $mount) {
1616
-				$mountPoint = $mount->getMountPoint();
1617
-				$storage = $mount->getStorage();
1618
-				if ($storage) {
1619
-					$cache = $storage->getCache('');
1620
-
1621
-					$relativeMountPoint = substr($mountPoint, $rootLength);
1622
-					$results = call_user_func_array(array($cache, $method), $args);
1623
-					if ($results) {
1624
-						foreach ($results as $result) {
1625
-							$internalPath = $result['path'];
1626
-							$result['path'] = rtrim($relativeMountPoint . $result['path'], '/');
1627
-							$path = rtrim($mountPoint . $internalPath, '/');
1628
-							$owner = \OC::$server->getUserManager()->get($storage->getOwner($internalPath));
1629
-							$files[] = new FileInfo($path, $storage, $internalPath, $result, $mount, $owner);
1630
-						}
1631
-					}
1632
-				}
1633
-			}
1634
-		}
1635
-		return $files;
1636
-	}
1637
-
1638
-	/**
1639
-	 * Get the owner for a file or folder
1640
-	 *
1641
-	 * @param string $path
1642
-	 * @return string the user id of the owner
1643
-	 * @throws NotFoundException
1644
-	 */
1645
-	public function getOwner($path) {
1646
-		$info = $this->getFileInfo($path);
1647
-		if (!$info) {
1648
-			throw new NotFoundException($path . ' not found while trying to get owner');
1649
-		}
1650
-		return $info->getOwner()->getUID();
1651
-	}
1652
-
1653
-	/**
1654
-	 * get the ETag for a file or folder
1655
-	 *
1656
-	 * @param string $path
1657
-	 * @return string
1658
-	 */
1659
-	public function getETag($path) {
1660
-		/**
1661
-		 * @var Storage\Storage $storage
1662
-		 * @var string $internalPath
1663
-		 */
1664
-		list($storage, $internalPath) = $this->resolvePath($path);
1665
-		if ($storage) {
1666
-			return $storage->getETag($internalPath);
1667
-		} else {
1668
-			return null;
1669
-		}
1670
-	}
1671
-
1672
-	/**
1673
-	 * Get the path of a file by id, relative to the view
1674
-	 *
1675
-	 * Note that the resulting path is not guarantied to be unique for the id, multiple paths can point to the same file
1676
-	 *
1677
-	 * @param int $id
1678
-	 * @throws NotFoundException
1679
-	 * @return string
1680
-	 */
1681
-	public function getPath($id) {
1682
-		$id = (int)$id;
1683
-		$manager = Filesystem::getMountManager();
1684
-		$mounts = $manager->findIn($this->fakeRoot);
1685
-		$mounts[] = $manager->find($this->fakeRoot);
1686
-		// reverse the array so we start with the storage this view is in
1687
-		// which is the most likely to contain the file we're looking for
1688
-		$mounts = array_reverse($mounts);
1689
-		foreach ($mounts as $mount) {
1690
-			/**
1691
-			 * @var \OC\Files\Mount\MountPoint $mount
1692
-			 */
1693
-			if ($mount->getStorage()) {
1694
-				$cache = $mount->getStorage()->getCache();
1695
-				$internalPath = $cache->getPathById($id);
1696
-				if (is_string($internalPath)) {
1697
-					$fullPath = $mount->getMountPoint() . $internalPath;
1698
-					if (!is_null($path = $this->getRelativePath($fullPath))) {
1699
-						return $path;
1700
-					}
1701
-				}
1702
-			}
1703
-		}
1704
-		throw new NotFoundException(sprintf('File with id "%s" has not been found.', $id));
1705
-	}
1706
-
1707
-	/**
1708
-	 * @param string $path
1709
-	 * @throws InvalidPathException
1710
-	 */
1711
-	private function assertPathLength($path) {
1712
-		$maxLen = min(PHP_MAXPATHLEN, 4000);
1713
-		// Check for the string length - performed using isset() instead of strlen()
1714
-		// because isset() is about 5x-40x faster.
1715
-		if (isset($path[$maxLen])) {
1716
-			$pathLen = strlen($path);
1717
-			throw new \OCP\Files\InvalidPathException("Path length($pathLen) exceeds max path length($maxLen): $path");
1718
-		}
1719
-	}
1720
-
1721
-	/**
1722
-	 * check if it is allowed to move a mount point to a given target.
1723
-	 * It is not allowed to move a mount point into a different mount point or
1724
-	 * into an already shared folder
1725
-	 *
1726
-	 * @param string $target path
1727
-	 * @return boolean
1728
-	 */
1729
-	private function isTargetAllowed($target) {
1730
-
1731
-		list($targetStorage, $targetInternalPath) = \OC\Files\Filesystem::resolvePath($target);
1732
-		if (!$targetStorage->instanceOfStorage('\OCP\Files\IHomeStorage')) {
1733
-			\OCP\Util::writeLog('files',
1734
-				'It is not allowed to move one mount point into another one',
1735
-				\OCP\Util::DEBUG);
1736
-			return false;
1737
-		}
1738
-
1739
-		// note: cannot use the view because the target is already locked
1740
-		$fileId = (int)$targetStorage->getCache()->getId($targetInternalPath);
1741
-		if ($fileId === -1) {
1742
-			// target might not exist, need to check parent instead
1743
-			$fileId = (int)$targetStorage->getCache()->getId(dirname($targetInternalPath));
1744
-		}
1745
-
1746
-		// check if any of the parents were shared by the current owner (include collections)
1747
-		$shares = \OCP\Share::getItemShared(
1748
-			'folder',
1749
-			$fileId,
1750
-			\OCP\Share::FORMAT_NONE,
1751
-			null,
1752
-			true
1753
-		);
1754
-
1755
-		if (count($shares) > 0) {
1756
-			\OCP\Util::writeLog('files',
1757
-				'It is not allowed to move one mount point into a shared folder',
1758
-				\OCP\Util::DEBUG);
1759
-			return false;
1760
-		}
1761
-
1762
-		return true;
1763
-	}
1764
-
1765
-	/**
1766
-	 * Get a fileinfo object for files that are ignored in the cache (part files)
1767
-	 *
1768
-	 * @param string $path
1769
-	 * @return \OCP\Files\FileInfo
1770
-	 */
1771
-	private function getPartFileInfo($path) {
1772
-		$mount = $this->getMount($path);
1773
-		$storage = $mount->getStorage();
1774
-		$internalPath = $mount->getInternalPath($this->getAbsolutePath($path));
1775
-		$owner = \OC::$server->getUserManager()->get($storage->getOwner($internalPath));
1776
-		return new FileInfo(
1777
-			$this->getAbsolutePath($path),
1778
-			$storage,
1779
-			$internalPath,
1780
-			[
1781
-				'fileid' => null,
1782
-				'mimetype' => $storage->getMimeType($internalPath),
1783
-				'name' => basename($path),
1784
-				'etag' => null,
1785
-				'size' => $storage->filesize($internalPath),
1786
-				'mtime' => $storage->filemtime($internalPath),
1787
-				'encrypted' => false,
1788
-				'permissions' => \OCP\Constants::PERMISSION_ALL
1789
-			],
1790
-			$mount,
1791
-			$owner
1792
-		);
1793
-	}
1794
-
1795
-	/**
1796
-	 * @param string $path
1797
-	 * @param string $fileName
1798
-	 * @throws InvalidPathException
1799
-	 */
1800
-	public function verifyPath($path, $fileName) {
1801
-		try {
1802
-			/** @type \OCP\Files\Storage $storage */
1803
-			list($storage, $internalPath) = $this->resolvePath($path);
1804
-			$storage->verifyPath($internalPath, $fileName);
1805
-		} catch (ReservedWordException $ex) {
1806
-			$l = \OC::$server->getL10N('lib');
1807
-			throw new InvalidPathException($l->t('File name is a reserved word'));
1808
-		} catch (InvalidCharacterInPathException $ex) {
1809
-			$l = \OC::$server->getL10N('lib');
1810
-			throw new InvalidPathException($l->t('File name contains at least one invalid character'));
1811
-		} catch (FileNameTooLongException $ex) {
1812
-			$l = \OC::$server->getL10N('lib');
1813
-			throw new InvalidPathException($l->t('File name is too long'));
1814
-		} catch (InvalidDirectoryException $ex) {
1815
-			$l = \OC::$server->getL10N('lib');
1816
-			throw new InvalidPathException($l->t('Dot files are not allowed'));
1817
-		} catch (EmptyFileNameException $ex) {
1818
-			$l = \OC::$server->getL10N('lib');
1819
-			throw new InvalidPathException($l->t('Empty filename is not allowed'));
1820
-		}
1821
-	}
1822
-
1823
-	/**
1824
-	 * get all parent folders of $path
1825
-	 *
1826
-	 * @param string $path
1827
-	 * @return string[]
1828
-	 */
1829
-	private function getParents($path) {
1830
-		$path = trim($path, '/');
1831
-		if (!$path) {
1832
-			return [];
1833
-		}
1834
-
1835
-		$parts = explode('/', $path);
1836
-
1837
-		// remove the single file
1838
-		array_pop($parts);
1839
-		$result = array('/');
1840
-		$resultPath = '';
1841
-		foreach ($parts as $part) {
1842
-			if ($part) {
1843
-				$resultPath .= '/' . $part;
1844
-				$result[] = $resultPath;
1845
-			}
1846
-		}
1847
-		return $result;
1848
-	}
1849
-
1850
-	/**
1851
-	 * Returns the mount point for which to lock
1852
-	 *
1853
-	 * @param string $absolutePath absolute path
1854
-	 * @param bool $useParentMount true to return parent mount instead of whatever
1855
-	 * is mounted directly on the given path, false otherwise
1856
-	 * @return \OC\Files\Mount\MountPoint mount point for which to apply locks
1857
-	 */
1858
-	private function getMountForLock($absolutePath, $useParentMount = false) {
1859
-		$results = [];
1860
-		$mount = Filesystem::getMountManager()->find($absolutePath);
1861
-		if (!$mount) {
1862
-			return $results;
1863
-		}
1864
-
1865
-		if ($useParentMount) {
1866
-			// find out if something is mounted directly on the path
1867
-			$internalPath = $mount->getInternalPath($absolutePath);
1868
-			if ($internalPath === '') {
1869
-				// resolve the parent mount instead
1870
-				$mount = Filesystem::getMountManager()->find(dirname($absolutePath));
1871
-			}
1872
-		}
1873
-
1874
-		return $mount;
1875
-	}
1876
-
1877
-	/**
1878
-	 * Lock the given path
1879
-	 *
1880
-	 * @param string $path the path of the file to lock, relative to the view
1881
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
1882
-	 * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage
1883
-	 *
1884
-	 * @return bool False if the path is excluded from locking, true otherwise
1885
-	 * @throws \OCP\Lock\LockedException if the path is already locked
1886
-	 */
1887
-	private function lockPath($path, $type, $lockMountPoint = false) {
1888
-		$absolutePath = $this->getAbsolutePath($path);
1889
-		$absolutePath = Filesystem::normalizePath($absolutePath);
1890
-		if (!$this->shouldLockFile($absolutePath)) {
1891
-			return false;
1892
-		}
1893
-
1894
-		$mount = $this->getMountForLock($absolutePath, $lockMountPoint);
1895
-		if ($mount) {
1896
-			try {
1897
-				$storage = $mount->getStorage();
1898
-				if ($storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
1899
-					$storage->acquireLock(
1900
-						$mount->getInternalPath($absolutePath),
1901
-						$type,
1902
-						$this->lockingProvider
1903
-					);
1904
-				}
1905
-			} catch (\OCP\Lock\LockedException $e) {
1906
-				// rethrow with the a human-readable path
1907
-				throw new \OCP\Lock\LockedException(
1908
-					$this->getPathRelativeToFiles($absolutePath),
1909
-					$e
1910
-				);
1911
-			}
1912
-		}
1913
-
1914
-		return true;
1915
-	}
1916
-
1917
-	/**
1918
-	 * Change the lock type
1919
-	 *
1920
-	 * @param string $path the path of the file to lock, relative to the view
1921
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
1922
-	 * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage
1923
-	 *
1924
-	 * @return bool False if the path is excluded from locking, true otherwise
1925
-	 * @throws \OCP\Lock\LockedException if the path is already locked
1926
-	 */
1927
-	public function changeLock($path, $type, $lockMountPoint = false) {
1928
-		$path = Filesystem::normalizePath($path);
1929
-		$absolutePath = $this->getAbsolutePath($path);
1930
-		$absolutePath = Filesystem::normalizePath($absolutePath);
1931
-		if (!$this->shouldLockFile($absolutePath)) {
1932
-			return false;
1933
-		}
1934
-
1935
-		$mount = $this->getMountForLock($absolutePath, $lockMountPoint);
1936
-		if ($mount) {
1937
-			try {
1938
-				$storage = $mount->getStorage();
1939
-				if ($storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
1940
-					$storage->changeLock(
1941
-						$mount->getInternalPath($absolutePath),
1942
-						$type,
1943
-						$this->lockingProvider
1944
-					);
1945
-				}
1946
-			} catch (\OCP\Lock\LockedException $e) {
1947
-				// rethrow with the a human-readable path
1948
-				throw new \OCP\Lock\LockedException(
1949
-					$this->getPathRelativeToFiles($absolutePath),
1950
-					$e
1951
-				);
1952
-			}
1953
-		}
1954
-
1955
-		return true;
1956
-	}
1957
-
1958
-	/**
1959
-	 * Unlock the given path
1960
-	 *
1961
-	 * @param string $path the path of the file to unlock, relative to the view
1962
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
1963
-	 * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage
1964
-	 *
1965
-	 * @return bool False if the path is excluded from locking, true otherwise
1966
-	 */
1967
-	private function unlockPath($path, $type, $lockMountPoint = false) {
1968
-		$absolutePath = $this->getAbsolutePath($path);
1969
-		$absolutePath = Filesystem::normalizePath($absolutePath);
1970
-		if (!$this->shouldLockFile($absolutePath)) {
1971
-			return false;
1972
-		}
1973
-
1974
-		$mount = $this->getMountForLock($absolutePath, $lockMountPoint);
1975
-		if ($mount) {
1976
-			$storage = $mount->getStorage();
1977
-			if ($storage && $storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
1978
-				$storage->releaseLock(
1979
-					$mount->getInternalPath($absolutePath),
1980
-					$type,
1981
-					$this->lockingProvider
1982
-				);
1983
-			}
1984
-		}
1985
-
1986
-		return true;
1987
-	}
1988
-
1989
-	/**
1990
-	 * Lock a path and all its parents up to the root of the view
1991
-	 *
1992
-	 * @param string $path the path of the file to lock relative to the view
1993
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
1994
-	 * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage
1995
-	 *
1996
-	 * @return bool False if the path is excluded from locking, true otherwise
1997
-	 */
1998
-	public function lockFile($path, $type, $lockMountPoint = false) {
1999
-		$absolutePath = $this->getAbsolutePath($path);
2000
-		$absolutePath = Filesystem::normalizePath($absolutePath);
2001
-		if (!$this->shouldLockFile($absolutePath)) {
2002
-			return false;
2003
-		}
2004
-
2005
-		$this->lockPath($path, $type, $lockMountPoint);
2006
-
2007
-		$parents = $this->getParents($path);
2008
-		foreach ($parents as $parent) {
2009
-			$this->lockPath($parent, ILockingProvider::LOCK_SHARED);
2010
-		}
2011
-
2012
-		return true;
2013
-	}
2014
-
2015
-	/**
2016
-	 * Unlock a path and all its parents up to the root of the view
2017
-	 *
2018
-	 * @param string $path the path of the file to lock relative to the view
2019
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
2020
-	 * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage
2021
-	 *
2022
-	 * @return bool False if the path is excluded from locking, true otherwise
2023
-	 */
2024
-	public function unlockFile($path, $type, $lockMountPoint = false) {
2025
-		$absolutePath = $this->getAbsolutePath($path);
2026
-		$absolutePath = Filesystem::normalizePath($absolutePath);
2027
-		if (!$this->shouldLockFile($absolutePath)) {
2028
-			return false;
2029
-		}
2030
-
2031
-		$this->unlockPath($path, $type, $lockMountPoint);
2032
-
2033
-		$parents = $this->getParents($path);
2034
-		foreach ($parents as $parent) {
2035
-			$this->unlockPath($parent, ILockingProvider::LOCK_SHARED);
2036
-		}
2037
-
2038
-		return true;
2039
-	}
2040
-
2041
-	/**
2042
-	 * Only lock files in data/user/files/
2043
-	 *
2044
-	 * @param string $path Absolute path to the file/folder we try to (un)lock
2045
-	 * @return bool
2046
-	 */
2047
-	protected function shouldLockFile($path) {
2048
-		$path = Filesystem::normalizePath($path);
2049
-
2050
-		$pathSegments = explode('/', $path);
2051
-		if (isset($pathSegments[2])) {
2052
-			// E.g.: /username/files/path-to-file
2053
-			return ($pathSegments[2] === 'files') && (count($pathSegments) > 3);
2054
-		}
2055
-
2056
-		return true;
2057
-	}
2058
-
2059
-	/**
2060
-	 * Shortens the given absolute path to be relative to
2061
-	 * "$user/files".
2062
-	 *
2063
-	 * @param string $absolutePath absolute path which is under "files"
2064
-	 *
2065
-	 * @return string path relative to "files" with trimmed slashes or null
2066
-	 * if the path was NOT relative to files
2067
-	 *
2068
-	 * @throws \InvalidArgumentException if the given path was not under "files"
2069
-	 * @since 8.1.0
2070
-	 */
2071
-	public function getPathRelativeToFiles($absolutePath) {
2072
-		$path = Filesystem::normalizePath($absolutePath);
2073
-		$parts = explode('/', trim($path, '/'), 3);
2074
-		// "$user", "files", "path/to/dir"
2075
-		if (!isset($parts[1]) || $parts[1] !== 'files') {
2076
-			$this->logger->error(
2077
-				'$absolutePath must be relative to "files", value is "%s"',
2078
-				[
2079
-					$absolutePath
2080
-				]
2081
-			);
2082
-			throw new \InvalidArgumentException('$absolutePath must be relative to "files"');
2083
-		}
2084
-		if (isset($parts[2])) {
2085
-			return $parts[2];
2086
-		}
2087
-		return '';
2088
-	}
2089
-
2090
-	/**
2091
-	 * @param string $filename
2092
-	 * @return array
2093
-	 * @throws \OC\User\NoUserException
2094
-	 * @throws NotFoundException
2095
-	 */
2096
-	public function getUidAndFilename($filename) {
2097
-		$info = $this->getFileInfo($filename);
2098
-		if (!$info instanceof \OCP\Files\FileInfo) {
2099
-			throw new NotFoundException($this->getAbsolutePath($filename) . ' not found');
2100
-		}
2101
-		$uid = $info->getOwner()->getUID();
2102
-		if ($uid != \OCP\User::getUser()) {
2103
-			Filesystem::initMountPoints($uid);
2104
-			$ownerView = new View('/' . $uid . '/files');
2105
-			try {
2106
-				$filename = $ownerView->getPath($info['fileid']);
2107
-			} catch (NotFoundException $e) {
2108
-				throw new NotFoundException('File with id ' . $info['fileid'] . ' not found for user ' . $uid);
2109
-			}
2110
-		}
2111
-		return [$uid, $filename];
2112
-	}
2113
-
2114
-	/**
2115
-	 * Creates parent non-existing folders
2116
-	 *
2117
-	 * @param string $filePath
2118
-	 * @return bool
2119
-	 */
2120
-	private function createParentDirectories($filePath) {
2121
-		$directoryParts = explode('/', $filePath);
2122
-		$directoryParts = array_filter($directoryParts);
2123
-		foreach ($directoryParts as $key => $part) {
2124
-			$currentPathElements = array_slice($directoryParts, 0, $key);
2125
-			$currentPath = '/' . implode('/', $currentPathElements);
2126
-			if ($this->is_file($currentPath)) {
2127
-				return false;
2128
-			}
2129
-			if (!$this->file_exists($currentPath)) {
2130
-				$this->mkdir($currentPath);
2131
-			}
2132
-		}
2133
-
2134
-		return true;
2135
-	}
87
+    /** @var string */
88
+    private $fakeRoot = '';
89
+
90
+    /**
91
+     * @var \OCP\Lock\ILockingProvider
92
+     */
93
+    private $lockingProvider;
94
+
95
+    private $lockingEnabled;
96
+
97
+    private $updaterEnabled = true;
98
+
99
+    /** @var \OC\User\Manager */
100
+    private $userManager;
101
+
102
+    /** @var \OCP\ILogger */
103
+    private $logger;
104
+
105
+    /**
106
+     * @param string $root
107
+     * @throws \Exception If $root contains an invalid path
108
+     */
109
+    public function __construct($root = '') {
110
+        if (is_null($root)) {
111
+            throw new \InvalidArgumentException('Root can\'t be null');
112
+        }
113
+        if (!Filesystem::isValidPath($root)) {
114
+            throw new \Exception();
115
+        }
116
+
117
+        $this->fakeRoot = $root;
118
+        $this->lockingProvider = \OC::$server->getLockingProvider();
119
+        $this->lockingEnabled = !($this->lockingProvider instanceof \OC\Lock\NoopLockingProvider);
120
+        $this->userManager = \OC::$server->getUserManager();
121
+        $this->logger = \OC::$server->getLogger();
122
+    }
123
+
124
+    public function getAbsolutePath($path = '/') {
125
+        if ($path === null) {
126
+            return null;
127
+        }
128
+        $this->assertPathLength($path);
129
+        if ($path === '') {
130
+            $path = '/';
131
+        }
132
+        if ($path[0] !== '/') {
133
+            $path = '/' . $path;
134
+        }
135
+        return $this->fakeRoot . $path;
136
+    }
137
+
138
+    /**
139
+     * change the root to a fake root
140
+     *
141
+     * @param string $fakeRoot
142
+     * @return boolean|null
143
+     */
144
+    public function chroot($fakeRoot) {
145
+        if (!$fakeRoot == '') {
146
+            if ($fakeRoot[0] !== '/') {
147
+                $fakeRoot = '/' . $fakeRoot;
148
+            }
149
+        }
150
+        $this->fakeRoot = $fakeRoot;
151
+    }
152
+
153
+    /**
154
+     * get the fake root
155
+     *
156
+     * @return string
157
+     */
158
+    public function getRoot() {
159
+        return $this->fakeRoot;
160
+    }
161
+
162
+    /**
163
+     * get path relative to the root of the view
164
+     *
165
+     * @param string $path
166
+     * @return string
167
+     */
168
+    public function getRelativePath($path) {
169
+        $this->assertPathLength($path);
170
+        if ($this->fakeRoot == '') {
171
+            return $path;
172
+        }
173
+
174
+        if (rtrim($path, '/') === rtrim($this->fakeRoot, '/')) {
175
+            return '/';
176
+        }
177
+
178
+        // missing slashes can cause wrong matches!
179
+        $root = rtrim($this->fakeRoot, '/') . '/';
180
+
181
+        if (strpos($path, $root) !== 0) {
182
+            return null;
183
+        } else {
184
+            $path = substr($path, strlen($this->fakeRoot));
185
+            if (strlen($path) === 0) {
186
+                return '/';
187
+            } else {
188
+                return $path;
189
+            }
190
+        }
191
+    }
192
+
193
+    /**
194
+     * get the mountpoint of the storage object for a path
195
+     * ( note: because a storage is not always mounted inside the fakeroot, the
196
+     * returned mountpoint is relative to the absolute root of the filesystem
197
+     * and does not take the chroot into account )
198
+     *
199
+     * @param string $path
200
+     * @return string
201
+     */
202
+    public function getMountPoint($path) {
203
+        return Filesystem::getMountPoint($this->getAbsolutePath($path));
204
+    }
205
+
206
+    /**
207
+     * get the mountpoint of the storage object for a path
208
+     * ( note: because a storage is not always mounted inside the fakeroot, the
209
+     * returned mountpoint is relative to the absolute root of the filesystem
210
+     * and does not take the chroot into account )
211
+     *
212
+     * @param string $path
213
+     * @return \OCP\Files\Mount\IMountPoint
214
+     */
215
+    public function getMount($path) {
216
+        return Filesystem::getMountManager()->find($this->getAbsolutePath($path));
217
+    }
218
+
219
+    /**
220
+     * resolve a path to a storage and internal path
221
+     *
222
+     * @param string $path
223
+     * @return array an array consisting of the storage and the internal path
224
+     */
225
+    public function resolvePath($path) {
226
+        $a = $this->getAbsolutePath($path);
227
+        $p = Filesystem::normalizePath($a);
228
+        return Filesystem::resolvePath($p);
229
+    }
230
+
231
+    /**
232
+     * return the path to a local version of the file
233
+     * we need this because we can't know if a file is stored local or not from
234
+     * outside the filestorage and for some purposes a local file is needed
235
+     *
236
+     * @param string $path
237
+     * @return string
238
+     */
239
+    public function getLocalFile($path) {
240
+        $parent = substr($path, 0, strrpos($path, '/'));
241
+        $path = $this->getAbsolutePath($path);
242
+        list($storage, $internalPath) = Filesystem::resolvePath($path);
243
+        if (Filesystem::isValidPath($parent) and $storage) {
244
+            return $storage->getLocalFile($internalPath);
245
+        } else {
246
+            return null;
247
+        }
248
+    }
249
+
250
+    /**
251
+     * @param string $path
252
+     * @return string
253
+     */
254
+    public function getLocalFolder($path) {
255
+        $parent = substr($path, 0, strrpos($path, '/'));
256
+        $path = $this->getAbsolutePath($path);
257
+        list($storage, $internalPath) = Filesystem::resolvePath($path);
258
+        if (Filesystem::isValidPath($parent) and $storage) {
259
+            return $storage->getLocalFolder($internalPath);
260
+        } else {
261
+            return null;
262
+        }
263
+    }
264
+
265
+    /**
266
+     * the following functions operate with arguments and return values identical
267
+     * to those of their PHP built-in equivalents. Mostly they are merely wrappers
268
+     * for \OC\Files\Storage\Storage via basicOperation().
269
+     */
270
+    public function mkdir($path) {
271
+        return $this->basicOperation('mkdir', $path, array('create', 'write'));
272
+    }
273
+
274
+    /**
275
+     * remove mount point
276
+     *
277
+     * @param \OC\Files\Mount\MoveableMount $mount
278
+     * @param string $path relative to data/
279
+     * @return boolean
280
+     */
281
+    protected function removeMount($mount, $path) {
282
+        if ($mount instanceof MoveableMount) {
283
+            // cut of /user/files to get the relative path to data/user/files
284
+            $pathParts = explode('/', $path, 4);
285
+            $relPath = '/' . $pathParts[3];
286
+            $this->lockFile($relPath, ILockingProvider::LOCK_SHARED, true);
287
+            \OC_Hook::emit(
288
+                Filesystem::CLASSNAME, "umount",
289
+                array(Filesystem::signal_param_path => $relPath)
290
+            );
291
+            $this->changeLock($relPath, ILockingProvider::LOCK_EXCLUSIVE, true);
292
+            $result = $mount->removeMount();
293
+            $this->changeLock($relPath, ILockingProvider::LOCK_SHARED, true);
294
+            if ($result) {
295
+                \OC_Hook::emit(
296
+                    Filesystem::CLASSNAME, "post_umount",
297
+                    array(Filesystem::signal_param_path => $relPath)
298
+                );
299
+            }
300
+            $this->unlockFile($relPath, ILockingProvider::LOCK_SHARED, true);
301
+            return $result;
302
+        } else {
303
+            // do not allow deleting the storage's root / the mount point
304
+            // because for some storages it might delete the whole contents
305
+            // but isn't supposed to work that way
306
+            return false;
307
+        }
308
+    }
309
+
310
+    public function disableCacheUpdate() {
311
+        $this->updaterEnabled = false;
312
+    }
313
+
314
+    public function enableCacheUpdate() {
315
+        $this->updaterEnabled = true;
316
+    }
317
+
318
+    protected function writeUpdate(Storage $storage, $internalPath, $time = null) {
319
+        if ($this->updaterEnabled) {
320
+            if (is_null($time)) {
321
+                $time = time();
322
+            }
323
+            $storage->getUpdater()->update($internalPath, $time);
324
+        }
325
+    }
326
+
327
+    protected function removeUpdate(Storage $storage, $internalPath) {
328
+        if ($this->updaterEnabled) {
329
+            $storage->getUpdater()->remove($internalPath);
330
+        }
331
+    }
332
+
333
+    protected function renameUpdate(Storage $sourceStorage, Storage $targetStorage, $sourceInternalPath, $targetInternalPath) {
334
+        if ($this->updaterEnabled) {
335
+            $targetStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
336
+        }
337
+    }
338
+
339
+    /**
340
+     * @param string $path
341
+     * @return bool|mixed
342
+     */
343
+    public function rmdir($path) {
344
+        $absolutePath = $this->getAbsolutePath($path);
345
+        $mount = Filesystem::getMountManager()->find($absolutePath);
346
+        if ($mount->getInternalPath($absolutePath) === '') {
347
+            return $this->removeMount($mount, $absolutePath);
348
+        }
349
+        if ($this->is_dir($path)) {
350
+            $result = $this->basicOperation('rmdir', $path, array('delete'));
351
+        } else {
352
+            $result = false;
353
+        }
354
+
355
+        if (!$result && !$this->file_exists($path)) { //clear ghost files from the cache on delete
356
+            $storage = $mount->getStorage();
357
+            $internalPath = $mount->getInternalPath($absolutePath);
358
+            $storage->getUpdater()->remove($internalPath);
359
+        }
360
+        return $result;
361
+    }
362
+
363
+    /**
364
+     * @param string $path
365
+     * @return resource
366
+     */
367
+    public function opendir($path) {
368
+        return $this->basicOperation('opendir', $path, array('read'));
369
+    }
370
+
371
+    /**
372
+     * @param $handle
373
+     * @return mixed
374
+     */
375
+    public function readdir($handle) {
376
+        $fsLocal = new Storage\Local(array('datadir' => '/'));
377
+        return $fsLocal->readdir($handle);
378
+    }
379
+
380
+    /**
381
+     * @param string $path
382
+     * @return bool|mixed
383
+     */
384
+    public function is_dir($path) {
385
+        if ($path == '/') {
386
+            return true;
387
+        }
388
+        return $this->basicOperation('is_dir', $path);
389
+    }
390
+
391
+    /**
392
+     * @param string $path
393
+     * @return bool|mixed
394
+     */
395
+    public function is_file($path) {
396
+        if ($path == '/') {
397
+            return false;
398
+        }
399
+        return $this->basicOperation('is_file', $path);
400
+    }
401
+
402
+    /**
403
+     * @param string $path
404
+     * @return mixed
405
+     */
406
+    public function stat($path) {
407
+        return $this->basicOperation('stat', $path);
408
+    }
409
+
410
+    /**
411
+     * @param string $path
412
+     * @return mixed
413
+     */
414
+    public function filetype($path) {
415
+        return $this->basicOperation('filetype', $path);
416
+    }
417
+
418
+    /**
419
+     * @param string $path
420
+     * @return mixed
421
+     */
422
+    public function filesize($path) {
423
+        return $this->basicOperation('filesize', $path);
424
+    }
425
+
426
+    /**
427
+     * @param string $path
428
+     * @return bool|mixed
429
+     * @throws \OCP\Files\InvalidPathException
430
+     */
431
+    public function readfile($path) {
432
+        $this->assertPathLength($path);
433
+        @ob_end_clean();
434
+        $handle = $this->fopen($path, 'rb');
435
+        if ($handle) {
436
+            $chunkSize = 8192; // 8 kB chunks
437
+            while (!feof($handle)) {
438
+                echo fread($handle, $chunkSize);
439
+                flush();
440
+            }
441
+            fclose($handle);
442
+            $size = $this->filesize($path);
443
+            return $size;
444
+        }
445
+        return false;
446
+    }
447
+
448
+    /**
449
+     * @param string $path
450
+     * @param int $from
451
+     * @param int $to
452
+     * @return bool|mixed
453
+     * @throws \OCP\Files\InvalidPathException
454
+     * @throws \OCP\Files\UnseekableException
455
+     */
456
+    public function readfilePart($path, $from, $to) {
457
+        $this->assertPathLength($path);
458
+        @ob_end_clean();
459
+        $handle = $this->fopen($path, 'rb');
460
+        if ($handle) {
461
+            if (fseek($handle, $from) === 0) {
462
+                $chunkSize = 8192; // 8 kB chunks
463
+                $end = $to + 1;
464
+                while (!feof($handle) && ftell($handle) < $end) {
465
+                    $len = $end - ftell($handle);
466
+                    if ($len > $chunkSize) {
467
+                        $len = $chunkSize;
468
+                    }
469
+                    echo fread($handle, $len);
470
+                    flush();
471
+                }
472
+                $size = ftell($handle) - $from;
473
+                return $size;
474
+            }
475
+
476
+            throw new \OCP\Files\UnseekableException('fseek error');
477
+        }
478
+        return false;
479
+    }
480
+
481
+    /**
482
+     * @param string $path
483
+     * @return mixed
484
+     */
485
+    public function isCreatable($path) {
486
+        return $this->basicOperation('isCreatable', $path);
487
+    }
488
+
489
+    /**
490
+     * @param string $path
491
+     * @return mixed
492
+     */
493
+    public function isReadable($path) {
494
+        return $this->basicOperation('isReadable', $path);
495
+    }
496
+
497
+    /**
498
+     * @param string $path
499
+     * @return mixed
500
+     */
501
+    public function isUpdatable($path) {
502
+        return $this->basicOperation('isUpdatable', $path);
503
+    }
504
+
505
+    /**
506
+     * @param string $path
507
+     * @return bool|mixed
508
+     */
509
+    public function isDeletable($path) {
510
+        $absolutePath = $this->getAbsolutePath($path);
511
+        $mount = Filesystem::getMountManager()->find($absolutePath);
512
+        if ($mount->getInternalPath($absolutePath) === '') {
513
+            return $mount instanceof MoveableMount;
514
+        }
515
+        return $this->basicOperation('isDeletable', $path);
516
+    }
517
+
518
+    /**
519
+     * @param string $path
520
+     * @return mixed
521
+     */
522
+    public function isSharable($path) {
523
+        return $this->basicOperation('isSharable', $path);
524
+    }
525
+
526
+    /**
527
+     * @param string $path
528
+     * @return bool|mixed
529
+     */
530
+    public function file_exists($path) {
531
+        if ($path == '/') {
532
+            return true;
533
+        }
534
+        return $this->basicOperation('file_exists', $path);
535
+    }
536
+
537
+    /**
538
+     * @param string $path
539
+     * @return mixed
540
+     */
541
+    public function filemtime($path) {
542
+        return $this->basicOperation('filemtime', $path);
543
+    }
544
+
545
+    /**
546
+     * @param string $path
547
+     * @param int|string $mtime
548
+     * @return bool
549
+     */
550
+    public function touch($path, $mtime = null) {
551
+        if (!is_null($mtime) and !is_numeric($mtime)) {
552
+            $mtime = strtotime($mtime);
553
+        }
554
+
555
+        $hooks = array('touch');
556
+
557
+        if (!$this->file_exists($path)) {
558
+            $hooks[] = 'create';
559
+            $hooks[] = 'write';
560
+        }
561
+        $result = $this->basicOperation('touch', $path, $hooks, $mtime);
562
+        if (!$result) {
563
+            // If create file fails because of permissions on external storage like SMB folders,
564
+            // check file exists and return false if not.
565
+            if (!$this->file_exists($path)) {
566
+                return false;
567
+            }
568
+            if (is_null($mtime)) {
569
+                $mtime = time();
570
+            }
571
+            //if native touch fails, we emulate it by changing the mtime in the cache
572
+            $this->putFileInfo($path, array('mtime' => floor($mtime)));
573
+        }
574
+        return true;
575
+    }
576
+
577
+    /**
578
+     * @param string $path
579
+     * @return mixed
580
+     */
581
+    public function file_get_contents($path) {
582
+        return $this->basicOperation('file_get_contents', $path, array('read'));
583
+    }
584
+
585
+    /**
586
+     * @param bool $exists
587
+     * @param string $path
588
+     * @param bool $run
589
+     */
590
+    protected function emit_file_hooks_pre($exists, $path, &$run) {
591
+        if (!$exists) {
592
+            \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_create, array(
593
+                Filesystem::signal_param_path => $this->getHookPath($path),
594
+                Filesystem::signal_param_run => &$run,
595
+            ));
596
+        } else {
597
+            \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_update, array(
598
+                Filesystem::signal_param_path => $this->getHookPath($path),
599
+                Filesystem::signal_param_run => &$run,
600
+            ));
601
+        }
602
+        \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_write, array(
603
+            Filesystem::signal_param_path => $this->getHookPath($path),
604
+            Filesystem::signal_param_run => &$run,
605
+        ));
606
+    }
607
+
608
+    /**
609
+     * @param bool $exists
610
+     * @param string $path
611
+     */
612
+    protected function emit_file_hooks_post($exists, $path) {
613
+        if (!$exists) {
614
+            \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_post_create, array(
615
+                Filesystem::signal_param_path => $this->getHookPath($path),
616
+            ));
617
+        } else {
618
+            \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_post_update, array(
619
+                Filesystem::signal_param_path => $this->getHookPath($path),
620
+            ));
621
+        }
622
+        \OC_Hook::emit(Filesystem::CLASSNAME, Filesystem::signal_post_write, array(
623
+            Filesystem::signal_param_path => $this->getHookPath($path),
624
+        ));
625
+    }
626
+
627
+    /**
628
+     * @param string $path
629
+     * @param mixed $data
630
+     * @return bool|mixed
631
+     * @throws \Exception
632
+     */
633
+    public function file_put_contents($path, $data) {
634
+        if (is_resource($data)) { //not having to deal with streams in file_put_contents makes life easier
635
+            $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
636
+            if (Filesystem::isValidPath($path)
637
+                and !Filesystem::isFileBlacklisted($path)
638
+            ) {
639
+                $path = $this->getRelativePath($absolutePath);
640
+
641
+                $this->lockFile($path, ILockingProvider::LOCK_SHARED);
642
+
643
+                $exists = $this->file_exists($path);
644
+                $run = true;
645
+                if ($this->shouldEmitHooks($path)) {
646
+                    $this->emit_file_hooks_pre($exists, $path, $run);
647
+                }
648
+                if (!$run) {
649
+                    $this->unlockFile($path, ILockingProvider::LOCK_SHARED);
650
+                    return false;
651
+                }
652
+
653
+                $this->changeLock($path, ILockingProvider::LOCK_EXCLUSIVE);
654
+
655
+                /** @var \OC\Files\Storage\Storage $storage */
656
+                list($storage, $internalPath) = $this->resolvePath($path);
657
+                $target = $storage->fopen($internalPath, 'w');
658
+                if ($target) {
659
+                    list (, $result) = \OC_Helper::streamCopy($data, $target);
660
+                    fclose($target);
661
+                    fclose($data);
662
+
663
+                    $this->writeUpdate($storage, $internalPath);
664
+
665
+                    $this->changeLock($path, ILockingProvider::LOCK_SHARED);
666
+
667
+                    if ($this->shouldEmitHooks($path) && $result !== false) {
668
+                        $this->emit_file_hooks_post($exists, $path);
669
+                    }
670
+                    $this->unlockFile($path, ILockingProvider::LOCK_SHARED);
671
+                    return $result;
672
+                } else {
673
+                    $this->unlockFile($path, ILockingProvider::LOCK_EXCLUSIVE);
674
+                    return false;
675
+                }
676
+            } else {
677
+                return false;
678
+            }
679
+        } else {
680
+            $hooks = ($this->file_exists($path)) ? array('update', 'write') : array('create', 'write');
681
+            return $this->basicOperation('file_put_contents', $path, $hooks, $data);
682
+        }
683
+    }
684
+
685
+    /**
686
+     * @param string $path
687
+     * @return bool|mixed
688
+     */
689
+    public function unlink($path) {
690
+        if ($path === '' || $path === '/') {
691
+            // do not allow deleting the root
692
+            return false;
693
+        }
694
+        $postFix = (substr($path, -1, 1) === '/') ? '/' : '';
695
+        $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
696
+        $mount = Filesystem::getMountManager()->find($absolutePath . $postFix);
697
+        if ($mount and $mount->getInternalPath($absolutePath) === '') {
698
+            return $this->removeMount($mount, $absolutePath);
699
+        }
700
+        if ($this->is_dir($path)) {
701
+            $result = $this->basicOperation('rmdir', $path, ['delete']);
702
+        } else {
703
+            $result = $this->basicOperation('unlink', $path, ['delete']);
704
+        }
705
+        if (!$result && !$this->file_exists($path)) { //clear ghost files from the cache on delete
706
+            $storage = $mount->getStorage();
707
+            $internalPath = $mount->getInternalPath($absolutePath);
708
+            $storage->getUpdater()->remove($internalPath);
709
+            return true;
710
+        } else {
711
+            return $result;
712
+        }
713
+    }
714
+
715
+    /**
716
+     * @param string $directory
717
+     * @return bool|mixed
718
+     */
719
+    public function deleteAll($directory) {
720
+        return $this->rmdir($directory);
721
+    }
722
+
723
+    /**
724
+     * Rename/move a file or folder from the source path to target path.
725
+     *
726
+     * @param string $path1 source path
727
+     * @param string $path2 target path
728
+     *
729
+     * @return bool|mixed
730
+     */
731
+    public function rename($path1, $path2) {
732
+        $absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1));
733
+        $absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($path2));
734
+        $result = false;
735
+        if (
736
+            Filesystem::isValidPath($path2)
737
+            and Filesystem::isValidPath($path1)
738
+            and !Filesystem::isFileBlacklisted($path2)
739
+        ) {
740
+            $path1 = $this->getRelativePath($absolutePath1);
741
+            $path2 = $this->getRelativePath($absolutePath2);
742
+            $exists = $this->file_exists($path2);
743
+
744
+            if ($path1 == null or $path2 == null) {
745
+                return false;
746
+            }
747
+
748
+            $this->lockFile($path1, ILockingProvider::LOCK_SHARED, true);
749
+            try {
750
+                $this->lockFile($path2, ILockingProvider::LOCK_SHARED, true);
751
+            } catch (LockedException $e) {
752
+                $this->unlockFile($path1, ILockingProvider::LOCK_SHARED);
753
+                throw $e;
754
+            }
755
+
756
+            $run = true;
757
+            if ($this->shouldEmitHooks($path1) && (Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2))) {
758
+                // if it was a rename from a part file to a regular file it was a write and not a rename operation
759
+                $this->emit_file_hooks_pre($exists, $path2, $run);
760
+            } elseif ($this->shouldEmitHooks($path1)) {
761
+                \OC_Hook::emit(
762
+                    Filesystem::CLASSNAME, Filesystem::signal_rename,
763
+                    array(
764
+                        Filesystem::signal_param_oldpath => $this->getHookPath($path1),
765
+                        Filesystem::signal_param_newpath => $this->getHookPath($path2),
766
+                        Filesystem::signal_param_run => &$run
767
+                    )
768
+                );
769
+            }
770
+            if ($run) {
771
+                $this->verifyPath(dirname($path2), basename($path2));
772
+
773
+                $manager = Filesystem::getMountManager();
774
+                $mount1 = $this->getMount($path1);
775
+                $mount2 = $this->getMount($path2);
776
+                $storage1 = $mount1->getStorage();
777
+                $storage2 = $mount2->getStorage();
778
+                $internalPath1 = $mount1->getInternalPath($absolutePath1);
779
+                $internalPath2 = $mount2->getInternalPath($absolutePath2);
780
+
781
+                $this->changeLock($path1, ILockingProvider::LOCK_EXCLUSIVE, true);
782
+                $this->changeLock($path2, ILockingProvider::LOCK_EXCLUSIVE, true);
783
+
784
+                if ($internalPath1 === '' and $mount1 instanceof MoveableMount) {
785
+                    if ($this->isTargetAllowed($absolutePath2)) {
786
+                        /**
787
+                         * @var \OC\Files\Mount\MountPoint | \OC\Files\Mount\MoveableMount $mount1
788
+                         */
789
+                        $sourceMountPoint = $mount1->getMountPoint();
790
+                        $result = $mount1->moveMount($absolutePath2);
791
+                        $manager->moveMount($sourceMountPoint, $mount1->getMountPoint());
792
+                    } else {
793
+                        $result = false;
794
+                    }
795
+                    // moving a file/folder within the same mount point
796
+                } elseif ($storage1 === $storage2) {
797
+                    if ($storage1) {
798
+                        $result = $storage1->rename($internalPath1, $internalPath2);
799
+                    } else {
800
+                        $result = false;
801
+                    }
802
+                    // moving a file/folder between storages (from $storage1 to $storage2)
803
+                } else {
804
+                    $result = $storage2->moveFromStorage($storage1, $internalPath1, $internalPath2);
805
+                }
806
+
807
+                if ((Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2)) && $result !== false) {
808
+                    // if it was a rename from a part file to a regular file it was a write and not a rename operation
809
+
810
+                    $this->writeUpdate($storage2, $internalPath2);
811
+                } else if ($result) {
812
+                    if ($internalPath1 !== '') { // don't do a cache update for moved mounts
813
+                        $this->renameUpdate($storage1, $storage2, $internalPath1, $internalPath2);
814
+                    }
815
+                }
816
+
817
+                $this->changeLock($path1, ILockingProvider::LOCK_SHARED, true);
818
+                $this->changeLock($path2, ILockingProvider::LOCK_SHARED, true);
819
+
820
+                if ((Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2)) && $result !== false) {
821
+                    if ($this->shouldEmitHooks()) {
822
+                        $this->emit_file_hooks_post($exists, $path2);
823
+                    }
824
+                } elseif ($result) {
825
+                    if ($this->shouldEmitHooks($path1) and $this->shouldEmitHooks($path2)) {
826
+                        \OC_Hook::emit(
827
+                            Filesystem::CLASSNAME,
828
+                            Filesystem::signal_post_rename,
829
+                            array(
830
+                                Filesystem::signal_param_oldpath => $this->getHookPath($path1),
831
+                                Filesystem::signal_param_newpath => $this->getHookPath($path2)
832
+                            )
833
+                        );
834
+                    }
835
+                }
836
+            }
837
+            $this->unlockFile($path1, ILockingProvider::LOCK_SHARED, true);
838
+            $this->unlockFile($path2, ILockingProvider::LOCK_SHARED, true);
839
+        }
840
+        return $result;
841
+    }
842
+
843
+    /**
844
+     * Copy a file/folder from the source path to target path
845
+     *
846
+     * @param string $path1 source path
847
+     * @param string $path2 target path
848
+     * @param bool $preserveMtime whether to preserve mtime on the copy
849
+     *
850
+     * @return bool|mixed
851
+     */
852
+    public function copy($path1, $path2, $preserveMtime = false) {
853
+        $absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1));
854
+        $absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($path2));
855
+        $result = false;
856
+        if (
857
+            Filesystem::isValidPath($path2)
858
+            and Filesystem::isValidPath($path1)
859
+            and !Filesystem::isFileBlacklisted($path2)
860
+        ) {
861
+            $path1 = $this->getRelativePath($absolutePath1);
862
+            $path2 = $this->getRelativePath($absolutePath2);
863
+
864
+            if ($path1 == null or $path2 == null) {
865
+                return false;
866
+            }
867
+            $run = true;
868
+
869
+            $this->lockFile($path2, ILockingProvider::LOCK_SHARED);
870
+            $this->lockFile($path1, ILockingProvider::LOCK_SHARED);
871
+            $lockTypePath1 = ILockingProvider::LOCK_SHARED;
872
+            $lockTypePath2 = ILockingProvider::LOCK_SHARED;
873
+
874
+            try {
875
+
876
+                $exists = $this->file_exists($path2);
877
+                if ($this->shouldEmitHooks()) {
878
+                    \OC_Hook::emit(
879
+                        Filesystem::CLASSNAME,
880
+                        Filesystem::signal_copy,
881
+                        array(
882
+                            Filesystem::signal_param_oldpath => $this->getHookPath($path1),
883
+                            Filesystem::signal_param_newpath => $this->getHookPath($path2),
884
+                            Filesystem::signal_param_run => &$run
885
+                        )
886
+                    );
887
+                    $this->emit_file_hooks_pre($exists, $path2, $run);
888
+                }
889
+                if ($run) {
890
+                    $mount1 = $this->getMount($path1);
891
+                    $mount2 = $this->getMount($path2);
892
+                    $storage1 = $mount1->getStorage();
893
+                    $internalPath1 = $mount1->getInternalPath($absolutePath1);
894
+                    $storage2 = $mount2->getStorage();
895
+                    $internalPath2 = $mount2->getInternalPath($absolutePath2);
896
+
897
+                    $this->changeLock($path2, ILockingProvider::LOCK_EXCLUSIVE);
898
+                    $lockTypePath2 = ILockingProvider::LOCK_EXCLUSIVE;
899
+
900
+                    if ($mount1->getMountPoint() == $mount2->getMountPoint()) {
901
+                        if ($storage1) {
902
+                            $result = $storage1->copy($internalPath1, $internalPath2);
903
+                        } else {
904
+                            $result = false;
905
+                        }
906
+                    } else {
907
+                        $result = $storage2->copyFromStorage($storage1, $internalPath1, $internalPath2);
908
+                    }
909
+
910
+                    $this->writeUpdate($storage2, $internalPath2);
911
+
912
+                    $this->changeLock($path2, ILockingProvider::LOCK_SHARED);
913
+                    $lockTypePath2 = ILockingProvider::LOCK_SHARED;
914
+
915
+                    if ($this->shouldEmitHooks() && $result !== false) {
916
+                        \OC_Hook::emit(
917
+                            Filesystem::CLASSNAME,
918
+                            Filesystem::signal_post_copy,
919
+                            array(
920
+                                Filesystem::signal_param_oldpath => $this->getHookPath($path1),
921
+                                Filesystem::signal_param_newpath => $this->getHookPath($path2)
922
+                            )
923
+                        );
924
+                        $this->emit_file_hooks_post($exists, $path2);
925
+                    }
926
+
927
+                }
928
+            } catch (\Exception $e) {
929
+                $this->unlockFile($path2, $lockTypePath2);
930
+                $this->unlockFile($path1, $lockTypePath1);
931
+                throw $e;
932
+            }
933
+
934
+            $this->unlockFile($path2, $lockTypePath2);
935
+            $this->unlockFile($path1, $lockTypePath1);
936
+
937
+        }
938
+        return $result;
939
+    }
940
+
941
+    /**
942
+     * @param string $path
943
+     * @param string $mode 'r' or 'w'
944
+     * @return resource
945
+     */
946
+    public function fopen($path, $mode) {
947
+        $mode = str_replace('b', '', $mode); // the binary flag is a windows only feature which we do not support
948
+        $hooks = array();
949
+        switch ($mode) {
950
+            case 'r':
951
+                $hooks[] = 'read';
952
+                break;
953
+            case 'r+':
954
+            case 'w+':
955
+            case 'x+':
956
+            case 'a+':
957
+                $hooks[] = 'read';
958
+                $hooks[] = 'write';
959
+                break;
960
+            case 'w':
961
+            case 'x':
962
+            case 'a':
963
+                $hooks[] = 'write';
964
+                break;
965
+            default:
966
+                \OCP\Util::writeLog('core', 'invalid mode (' . $mode . ') for ' . $path, \OCP\Util::ERROR);
967
+        }
968
+
969
+        if ($mode !== 'r' && $mode !== 'w') {
970
+            \OC::$server->getLogger()->info('Trying to open a file with a mode other than "r" or "w" can cause severe performance issues with some backends');
971
+        }
972
+
973
+        return $this->basicOperation('fopen', $path, $hooks, $mode);
974
+    }
975
+
976
+    /**
977
+     * @param string $path
978
+     * @return bool|string
979
+     * @throws \OCP\Files\InvalidPathException
980
+     */
981
+    public function toTmpFile($path) {
982
+        $this->assertPathLength($path);
983
+        if (Filesystem::isValidPath($path)) {
984
+            $source = $this->fopen($path, 'r');
985
+            if ($source) {
986
+                $extension = pathinfo($path, PATHINFO_EXTENSION);
987
+                $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($extension);
988
+                file_put_contents($tmpFile, $source);
989
+                return $tmpFile;
990
+            } else {
991
+                return false;
992
+            }
993
+        } else {
994
+            return false;
995
+        }
996
+    }
997
+
998
+    /**
999
+     * @param string $tmpFile
1000
+     * @param string $path
1001
+     * @return bool|mixed
1002
+     * @throws \OCP\Files\InvalidPathException
1003
+     */
1004
+    public function fromTmpFile($tmpFile, $path) {
1005
+        $this->assertPathLength($path);
1006
+        if (Filesystem::isValidPath($path)) {
1007
+
1008
+            // Get directory that the file is going into
1009
+            $filePath = dirname($path);
1010
+
1011
+            // Create the directories if any
1012
+            if (!$this->file_exists($filePath)) {
1013
+                $result = $this->createParentDirectories($filePath);
1014
+                if ($result === false) {
1015
+                    return false;
1016
+                }
1017
+            }
1018
+
1019
+            $source = fopen($tmpFile, 'r');
1020
+            if ($source) {
1021
+                $result = $this->file_put_contents($path, $source);
1022
+                // $this->file_put_contents() might have already closed
1023
+                // the resource, so we check it, before trying to close it
1024
+                // to avoid messages in the error log.
1025
+                if (is_resource($source)) {
1026
+                    fclose($source);
1027
+                }
1028
+                unlink($tmpFile);
1029
+                return $result;
1030
+            } else {
1031
+                return false;
1032
+            }
1033
+        } else {
1034
+            return false;
1035
+        }
1036
+    }
1037
+
1038
+
1039
+    /**
1040
+     * @param string $path
1041
+     * @return mixed
1042
+     * @throws \OCP\Files\InvalidPathException
1043
+     */
1044
+    public function getMimeType($path) {
1045
+        $this->assertPathLength($path);
1046
+        return $this->basicOperation('getMimeType', $path);
1047
+    }
1048
+
1049
+    /**
1050
+     * @param string $type
1051
+     * @param string $path
1052
+     * @param bool $raw
1053
+     * @return bool|null|string
1054
+     */
1055
+    public function hash($type, $path, $raw = false) {
1056
+        $postFix = (substr($path, -1, 1) === '/') ? '/' : '';
1057
+        $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
1058
+        if (Filesystem::isValidPath($path)) {
1059
+            $path = $this->getRelativePath($absolutePath);
1060
+            if ($path == null) {
1061
+                return false;
1062
+            }
1063
+            if ($this->shouldEmitHooks($path)) {
1064
+                \OC_Hook::emit(
1065
+                    Filesystem::CLASSNAME,
1066
+                    Filesystem::signal_read,
1067
+                    array(Filesystem::signal_param_path => $this->getHookPath($path))
1068
+                );
1069
+            }
1070
+            list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix);
1071
+            if ($storage) {
1072
+                $result = $storage->hash($type, $internalPath, $raw);
1073
+                return $result;
1074
+            }
1075
+        }
1076
+        return null;
1077
+    }
1078
+
1079
+    /**
1080
+     * @param string $path
1081
+     * @return mixed
1082
+     * @throws \OCP\Files\InvalidPathException
1083
+     */
1084
+    public function free_space($path = '/') {
1085
+        $this->assertPathLength($path);
1086
+        return $this->basicOperation('free_space', $path);
1087
+    }
1088
+
1089
+    /**
1090
+     * abstraction layer for basic filesystem functions: wrapper for \OC\Files\Storage\Storage
1091
+     *
1092
+     * @param string $operation
1093
+     * @param string $path
1094
+     * @param array $hooks (optional)
1095
+     * @param mixed $extraParam (optional)
1096
+     * @return mixed
1097
+     * @throws \Exception
1098
+     *
1099
+     * This method takes requests for basic filesystem functions (e.g. reading & writing
1100
+     * files), processes hooks and proxies, sanitises paths, and finally passes them on to
1101
+     * \OC\Files\Storage\Storage for delegation to a storage backend for execution
1102
+     */
1103
+    private function basicOperation($operation, $path, $hooks = [], $extraParam = null) {
1104
+        $postFix = (substr($path, -1, 1) === '/') ? '/' : '';
1105
+        $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
1106
+        if (Filesystem::isValidPath($path)
1107
+            and !Filesystem::isFileBlacklisted($path)
1108
+        ) {
1109
+            $path = $this->getRelativePath($absolutePath);
1110
+            if ($path == null) {
1111
+                return false;
1112
+            }
1113
+
1114
+            if (in_array('write', $hooks) || in_array('delete', $hooks) || in_array('read', $hooks)) {
1115
+                // always a shared lock during pre-hooks so the hook can read the file
1116
+                $this->lockFile($path, ILockingProvider::LOCK_SHARED);
1117
+            }
1118
+
1119
+            $run = $this->runHooks($hooks, $path);
1120
+            /** @var \OC\Files\Storage\Storage $storage */
1121
+            list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix);
1122
+            if ($run and $storage) {
1123
+                if (in_array('write', $hooks) || in_array('delete', $hooks)) {
1124
+                    $this->changeLock($path, ILockingProvider::LOCK_EXCLUSIVE);
1125
+                }
1126
+                try {
1127
+                    if (!is_null($extraParam)) {
1128
+                        $result = $storage->$operation($internalPath, $extraParam);
1129
+                    } else {
1130
+                        $result = $storage->$operation($internalPath);
1131
+                    }
1132
+                } catch (\Exception $e) {
1133
+                    if (in_array('write', $hooks) || in_array('delete', $hooks)) {
1134
+                        $this->unlockFile($path, ILockingProvider::LOCK_EXCLUSIVE);
1135
+                    } else if (in_array('read', $hooks)) {
1136
+                        $this->unlockFile($path, ILockingProvider::LOCK_SHARED);
1137
+                    }
1138
+                    throw $e;
1139
+                }
1140
+
1141
+                if ($result && in_array('delete', $hooks) and $result) {
1142
+                    $this->removeUpdate($storage, $internalPath);
1143
+                }
1144
+                if ($result && in_array('write', $hooks) and $operation !== 'fopen') {
1145
+                    $this->writeUpdate($storage, $internalPath);
1146
+                }
1147
+                if ($result && in_array('touch', $hooks)) {
1148
+                    $this->writeUpdate($storage, $internalPath, $extraParam);
1149
+                }
1150
+
1151
+                if ((in_array('write', $hooks) || in_array('delete', $hooks)) && ($operation !== 'fopen' || $result === false)) {
1152
+                    $this->changeLock($path, ILockingProvider::LOCK_SHARED);
1153
+                }
1154
+
1155
+                $unlockLater = false;
1156
+                if ($this->lockingEnabled && $operation === 'fopen' && is_resource($result)) {
1157
+                    $unlockLater = true;
1158
+                    // make sure our unlocking callback will still be called if connection is aborted
1159
+                    ignore_user_abort(true);
1160
+                    $result = CallbackWrapper::wrap($result, null, null, function () use ($hooks, $path) {
1161
+                        if (in_array('write', $hooks)) {
1162
+                            $this->unlockFile($path, ILockingProvider::LOCK_EXCLUSIVE);
1163
+                        } else if (in_array('read', $hooks)) {
1164
+                            $this->unlockFile($path, ILockingProvider::LOCK_SHARED);
1165
+                        }
1166
+                    });
1167
+                }
1168
+
1169
+                if ($this->shouldEmitHooks($path) && $result !== false) {
1170
+                    if ($operation != 'fopen') { //no post hooks for fopen, the file stream is still open
1171
+                        $this->runHooks($hooks, $path, true);
1172
+                    }
1173
+                }
1174
+
1175
+                if (!$unlockLater
1176
+                    && (in_array('write', $hooks) || in_array('delete', $hooks) || in_array('read', $hooks))
1177
+                ) {
1178
+                    $this->unlockFile($path, ILockingProvider::LOCK_SHARED);
1179
+                }
1180
+                return $result;
1181
+            } else {
1182
+                $this->unlockFile($path, ILockingProvider::LOCK_SHARED);
1183
+            }
1184
+        }
1185
+        return null;
1186
+    }
1187
+
1188
+    /**
1189
+     * get the path relative to the default root for hook usage
1190
+     *
1191
+     * @param string $path
1192
+     * @return string
1193
+     */
1194
+    private function getHookPath($path) {
1195
+        if (!Filesystem::getView()) {
1196
+            return $path;
1197
+        }
1198
+        return Filesystem::getView()->getRelativePath($this->getAbsolutePath($path));
1199
+    }
1200
+
1201
+    private function shouldEmitHooks($path = '') {
1202
+        if ($path && Cache\Scanner::isPartialFile($path)) {
1203
+            return false;
1204
+        }
1205
+        if (!Filesystem::$loaded) {
1206
+            return false;
1207
+        }
1208
+        $defaultRoot = Filesystem::getRoot();
1209
+        if ($defaultRoot === null) {
1210
+            return false;
1211
+        }
1212
+        if ($this->fakeRoot === $defaultRoot) {
1213
+            return true;
1214
+        }
1215
+        $fullPath = $this->getAbsolutePath($path);
1216
+
1217
+        if ($fullPath === $defaultRoot) {
1218
+            return true;
1219
+        }
1220
+
1221
+        return (strlen($fullPath) > strlen($defaultRoot)) && (substr($fullPath, 0, strlen($defaultRoot) + 1) === $defaultRoot . '/');
1222
+    }
1223
+
1224
+    /**
1225
+     * @param string[] $hooks
1226
+     * @param string $path
1227
+     * @param bool $post
1228
+     * @return bool
1229
+     */
1230
+    private function runHooks($hooks, $path, $post = false) {
1231
+        $relativePath = $path;
1232
+        $path = $this->getHookPath($path);
1233
+        $prefix = ($post) ? 'post_' : '';
1234
+        $run = true;
1235
+        if ($this->shouldEmitHooks($relativePath)) {
1236
+            foreach ($hooks as $hook) {
1237
+                if ($hook != 'read') {
1238
+                    \OC_Hook::emit(
1239
+                        Filesystem::CLASSNAME,
1240
+                        $prefix . $hook,
1241
+                        array(
1242
+                            Filesystem::signal_param_run => &$run,
1243
+                            Filesystem::signal_param_path => $path
1244
+                        )
1245
+                    );
1246
+                } elseif (!$post) {
1247
+                    \OC_Hook::emit(
1248
+                        Filesystem::CLASSNAME,
1249
+                        $prefix . $hook,
1250
+                        array(
1251
+                            Filesystem::signal_param_path => $path
1252
+                        )
1253
+                    );
1254
+                }
1255
+            }
1256
+        }
1257
+        return $run;
1258
+    }
1259
+
1260
+    /**
1261
+     * check if a file or folder has been updated since $time
1262
+     *
1263
+     * @param string $path
1264
+     * @param int $time
1265
+     * @return bool
1266
+     */
1267
+    public function hasUpdated($path, $time) {
1268
+        return $this->basicOperation('hasUpdated', $path, array(), $time);
1269
+    }
1270
+
1271
+    /**
1272
+     * @param string $ownerId
1273
+     * @return \OC\User\User
1274
+     */
1275
+    private function getUserObjectForOwner($ownerId) {
1276
+        $owner = $this->userManager->get($ownerId);
1277
+        if ($owner instanceof IUser) {
1278
+            return $owner;
1279
+        } else {
1280
+            return new User($ownerId, null);
1281
+        }
1282
+    }
1283
+
1284
+    /**
1285
+     * Get file info from cache
1286
+     *
1287
+     * If the file is not in cached it will be scanned
1288
+     * If the file has changed on storage the cache will be updated
1289
+     *
1290
+     * @param \OC\Files\Storage\Storage $storage
1291
+     * @param string $internalPath
1292
+     * @param string $relativePath
1293
+     * @return array|bool
1294
+     */
1295
+    private function getCacheEntry($storage, $internalPath, $relativePath) {
1296
+        $cache = $storage->getCache($internalPath);
1297
+        $data = $cache->get($internalPath);
1298
+        $watcher = $storage->getWatcher($internalPath);
1299
+
1300
+        try {
1301
+            // if the file is not in the cache or needs to be updated, trigger the scanner and reload the data
1302
+            if (!$data || $data['size'] === -1) {
1303
+                $this->lockFile($relativePath, ILockingProvider::LOCK_SHARED);
1304
+                if (!$storage->file_exists($internalPath)) {
1305
+                    $this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED);
1306
+                    return false;
1307
+                }
1308
+                $scanner = $storage->getScanner($internalPath);
1309
+                $scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
1310
+                $data = $cache->get($internalPath);
1311
+                $this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED);
1312
+            } else if (!Cache\Scanner::isPartialFile($internalPath) && $watcher->needsUpdate($internalPath, $data)) {
1313
+                $this->lockFile($relativePath, ILockingProvider::LOCK_SHARED);
1314
+                $watcher->update($internalPath, $data);
1315
+                $storage->getPropagator()->propagateChange($internalPath, time());
1316
+                $data = $cache->get($internalPath);
1317
+                $this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED);
1318
+            }
1319
+        } catch (LockedException $e) {
1320
+            // if the file is locked we just use the old cache info
1321
+        }
1322
+
1323
+        return $data;
1324
+    }
1325
+
1326
+    /**
1327
+     * get the filesystem info
1328
+     *
1329
+     * @param string $path
1330
+     * @param boolean|string $includeMountPoints true to add mountpoint sizes,
1331
+     * 'ext' to add only ext storage mount point sizes. Defaults to true.
1332
+     * defaults to true
1333
+     * @return \OC\Files\FileInfo|false False if file does not exist
1334
+     */
1335
+    public function getFileInfo($path, $includeMountPoints = true) {
1336
+        $this->assertPathLength($path);
1337
+        if (!Filesystem::isValidPath($path)) {
1338
+            return false;
1339
+        }
1340
+        if (Cache\Scanner::isPartialFile($path)) {
1341
+            return $this->getPartFileInfo($path);
1342
+        }
1343
+        $relativePath = $path;
1344
+        $path = Filesystem::normalizePath($this->fakeRoot . '/' . $path);
1345
+
1346
+        $mount = Filesystem::getMountManager()->find($path);
1347
+        $storage = $mount->getStorage();
1348
+        $internalPath = $mount->getInternalPath($path);
1349
+        if ($storage) {
1350
+            $data = $this->getCacheEntry($storage, $internalPath, $relativePath);
1351
+
1352
+            if (!$data instanceof ICacheEntry) {
1353
+                return false;
1354
+            }
1355
+
1356
+            if ($mount instanceof MoveableMount && $internalPath === '') {
1357
+                $data['permissions'] |= \OCP\Constants::PERMISSION_DELETE;
1358
+            }
1359
+
1360
+            $owner = $this->getUserObjectForOwner($storage->getOwner($internalPath));
1361
+            $info = new FileInfo($path, $storage, $internalPath, $data, $mount, $owner);
1362
+
1363
+            if ($data and isset($data['fileid'])) {
1364
+                if ($includeMountPoints and $data['mimetype'] === 'httpd/unix-directory') {
1365
+                    //add the sizes of other mount points to the folder
1366
+                    $extOnly = ($includeMountPoints === 'ext');
1367
+                    $mounts = Filesystem::getMountManager()->findIn($path);
1368
+                    $info->setSubMounts(array_filter($mounts, function (IMountPoint $mount) use ($extOnly) {
1369
+                        $subStorage = $mount->getStorage();
1370
+                        return !($extOnly && $subStorage instanceof \OCA\Files_Sharing\SharedStorage);
1371
+                    }));
1372
+                }
1373
+            }
1374
+
1375
+            return $info;
1376
+        }
1377
+
1378
+        return false;
1379
+    }
1380
+
1381
+    /**
1382
+     * get the content of a directory
1383
+     *
1384
+     * @param string $directory path under datadirectory
1385
+     * @param string $mimetype_filter limit returned content to this mimetype or mimepart
1386
+     * @return FileInfo[]
1387
+     */
1388
+    public function getDirectoryContent($directory, $mimetype_filter = '') {
1389
+        $this->assertPathLength($directory);
1390
+        if (!Filesystem::isValidPath($directory)) {
1391
+            return [];
1392
+        }
1393
+        $path = $this->getAbsolutePath($directory);
1394
+        $path = Filesystem::normalizePath($path);
1395
+        $mount = $this->getMount($directory);
1396
+        $storage = $mount->getStorage();
1397
+        $internalPath = $mount->getInternalPath($path);
1398
+        if ($storage) {
1399
+            $cache = $storage->getCache($internalPath);
1400
+            $user = \OC_User::getUser();
1401
+
1402
+            $data = $this->getCacheEntry($storage, $internalPath, $directory);
1403
+
1404
+            if (!$data instanceof ICacheEntry || !isset($data['fileid']) || !($data->getPermissions() && Constants::PERMISSION_READ)) {
1405
+                return [];
1406
+            }
1407
+
1408
+            $folderId = $data['fileid'];
1409
+            $contents = $cache->getFolderContentsById($folderId); //TODO: mimetype_filter
1410
+
1411
+            $sharingDisabled = \OCP\Util::isSharingDisabledForUser();
1412
+            /**
1413
+             * @var \OC\Files\FileInfo[] $files
1414
+             */
1415
+            $files = array_map(function (ICacheEntry $content) use ($path, $storage, $mount, $sharingDisabled) {
1416
+                if ($sharingDisabled) {
1417
+                    $content['permissions'] = $content['permissions'] & ~\OCP\Constants::PERMISSION_SHARE;
1418
+                }
1419
+                $owner = $this->getUserObjectForOwner($storage->getOwner($content['path']));
1420
+                return new FileInfo($path . '/' . $content['name'], $storage, $content['path'], $content, $mount, $owner);
1421
+            }, $contents);
1422
+
1423
+            //add a folder for any mountpoint in this directory and add the sizes of other mountpoints to the folders
1424
+            $mounts = Filesystem::getMountManager()->findIn($path);
1425
+            $dirLength = strlen($path);
1426
+            foreach ($mounts as $mount) {
1427
+                $mountPoint = $mount->getMountPoint();
1428
+                $subStorage = $mount->getStorage();
1429
+                if ($subStorage) {
1430
+                    $subCache = $subStorage->getCache('');
1431
+
1432
+                    $rootEntry = $subCache->get('');
1433
+                    if (!$rootEntry) {
1434
+                        $subScanner = $subStorage->getScanner('');
1435
+                        try {
1436
+                            $subScanner->scanFile('');
1437
+                        } catch (\OCP\Files\StorageNotAvailableException $e) {
1438
+                            continue;
1439
+                        } catch (\OCP\Files\StorageInvalidException $e) {
1440
+                            continue;
1441
+                        } catch (\Exception $e) {
1442
+                            // sometimes when the storage is not available it can be any exception
1443
+                            \OCP\Util::writeLog(
1444
+                                'core',
1445
+                                'Exception while scanning storage "' . $subStorage->getId() . '": ' .
1446
+                                get_class($e) . ': ' . $e->getMessage(),
1447
+                                \OCP\Util::ERROR
1448
+                            );
1449
+                            continue;
1450
+                        }
1451
+                        $rootEntry = $subCache->get('');
1452
+                    }
1453
+
1454
+                    if ($rootEntry && ($rootEntry->getPermissions() && Constants::PERMISSION_READ)) {
1455
+                        $relativePath = trim(substr($mountPoint, $dirLength), '/');
1456
+                        if ($pos = strpos($relativePath, '/')) {
1457
+                            //mountpoint inside subfolder add size to the correct folder
1458
+                            $entryName = substr($relativePath, 0, $pos);
1459
+                            foreach ($files as &$entry) {
1460
+                                if ($entry->getName() === $entryName) {
1461
+                                    $entry->addSubEntry($rootEntry, $mountPoint);
1462
+                                }
1463
+                            }
1464
+                        } else { //mountpoint in this folder, add an entry for it
1465
+                            $rootEntry['name'] = $relativePath;
1466
+                            $rootEntry['type'] = $rootEntry['mimetype'] === 'httpd/unix-directory' ? 'dir' : 'file';
1467
+                            $permissions = $rootEntry['permissions'];
1468
+                            // do not allow renaming/deleting the mount point if they are not shared files/folders
1469
+                            // for shared files/folders we use the permissions given by the owner
1470
+                            if ($mount instanceof MoveableMount) {
1471
+                                $rootEntry['permissions'] = $permissions | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE;
1472
+                            } else {
1473
+                                $rootEntry['permissions'] = $permissions & (\OCP\Constants::PERMISSION_ALL - (\OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE));
1474
+                            }
1475
+
1476
+                            //remove any existing entry with the same name
1477
+                            foreach ($files as $i => $file) {
1478
+                                if ($file['name'] === $rootEntry['name']) {
1479
+                                    unset($files[$i]);
1480
+                                    break;
1481
+                                }
1482
+                            }
1483
+                            $rootEntry['path'] = substr(Filesystem::normalizePath($path . '/' . $rootEntry['name']), strlen($user) + 2); // full path without /$user/
1484
+
1485
+                            // if sharing was disabled for the user we remove the share permissions
1486
+                            if (\OCP\Util::isSharingDisabledForUser()) {
1487
+                                $rootEntry['permissions'] = $rootEntry['permissions'] & ~\OCP\Constants::PERMISSION_SHARE;
1488
+                            }
1489
+
1490
+                            $owner = $this->getUserObjectForOwner($subStorage->getOwner(''));
1491
+                            $files[] = new FileInfo($path . '/' . $rootEntry['name'], $subStorage, '', $rootEntry, $mount, $owner);
1492
+                        }
1493
+                    }
1494
+                }
1495
+            }
1496
+
1497
+            if ($mimetype_filter) {
1498
+                $files = array_filter($files, function (FileInfo $file) use ($mimetype_filter) {
1499
+                    if (strpos($mimetype_filter, '/')) {
1500
+                        return $file->getMimetype() === $mimetype_filter;
1501
+                    } else {
1502
+                        return $file->getMimePart() === $mimetype_filter;
1503
+                    }
1504
+                });
1505
+            }
1506
+
1507
+            return $files;
1508
+        } else {
1509
+            return [];
1510
+        }
1511
+    }
1512
+
1513
+    /**
1514
+     * change file metadata
1515
+     *
1516
+     * @param string $path
1517
+     * @param array|\OCP\Files\FileInfo $data
1518
+     * @return int
1519
+     *
1520
+     * returns the fileid of the updated file
1521
+     */
1522
+    public function putFileInfo($path, $data) {
1523
+        $this->assertPathLength($path);
1524
+        if ($data instanceof FileInfo) {
1525
+            $data = $data->getData();
1526
+        }
1527
+        $path = Filesystem::normalizePath($this->fakeRoot . '/' . $path);
1528
+        /**
1529
+         * @var \OC\Files\Storage\Storage $storage
1530
+         * @var string $internalPath
1531
+         */
1532
+        list($storage, $internalPath) = Filesystem::resolvePath($path);
1533
+        if ($storage) {
1534
+            $cache = $storage->getCache($path);
1535
+
1536
+            if (!$cache->inCache($internalPath)) {
1537
+                $scanner = $storage->getScanner($internalPath);
1538
+                $scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW);
1539
+            }
1540
+
1541
+            return $cache->put($internalPath, $data);
1542
+        } else {
1543
+            return -1;
1544
+        }
1545
+    }
1546
+
1547
+    /**
1548
+     * search for files with the name matching $query
1549
+     *
1550
+     * @param string $query
1551
+     * @return FileInfo[]
1552
+     */
1553
+    public function search($query) {
1554
+        return $this->searchCommon('search', array('%' . $query . '%'));
1555
+    }
1556
+
1557
+    /**
1558
+     * search for files with the name matching $query
1559
+     *
1560
+     * @param string $query
1561
+     * @return FileInfo[]
1562
+     */
1563
+    public function searchRaw($query) {
1564
+        return $this->searchCommon('search', array($query));
1565
+    }
1566
+
1567
+    /**
1568
+     * search for files by mimetype
1569
+     *
1570
+     * @param string $mimetype
1571
+     * @return FileInfo[]
1572
+     */
1573
+    public function searchByMime($mimetype) {
1574
+        return $this->searchCommon('searchByMime', array($mimetype));
1575
+    }
1576
+
1577
+    /**
1578
+     * search for files by tag
1579
+     *
1580
+     * @param string|int $tag name or tag id
1581
+     * @param string $userId owner of the tags
1582
+     * @return FileInfo[]
1583
+     */
1584
+    public function searchByTag($tag, $userId) {
1585
+        return $this->searchCommon('searchByTag', array($tag, $userId));
1586
+    }
1587
+
1588
+    /**
1589
+     * @param string $method cache method
1590
+     * @param array $args
1591
+     * @return FileInfo[]
1592
+     */
1593
+    private function searchCommon($method, $args) {
1594
+        $files = array();
1595
+        $rootLength = strlen($this->fakeRoot);
1596
+
1597
+        $mount = $this->getMount('');
1598
+        $mountPoint = $mount->getMountPoint();
1599
+        $storage = $mount->getStorage();
1600
+        if ($storage) {
1601
+            $cache = $storage->getCache('');
1602
+
1603
+            $results = call_user_func_array(array($cache, $method), $args);
1604
+            foreach ($results as $result) {
1605
+                if (substr($mountPoint . $result['path'], 0, $rootLength + 1) === $this->fakeRoot . '/') {
1606
+                    $internalPath = $result['path'];
1607
+                    $path = $mountPoint . $result['path'];
1608
+                    $result['path'] = substr($mountPoint . $result['path'], $rootLength);
1609
+                    $owner = \OC::$server->getUserManager()->get($storage->getOwner($internalPath));
1610
+                    $files[] = new FileInfo($path, $storage, $internalPath, $result, $mount, $owner);
1611
+                }
1612
+            }
1613
+
1614
+            $mounts = Filesystem::getMountManager()->findIn($this->fakeRoot);
1615
+            foreach ($mounts as $mount) {
1616
+                $mountPoint = $mount->getMountPoint();
1617
+                $storage = $mount->getStorage();
1618
+                if ($storage) {
1619
+                    $cache = $storage->getCache('');
1620
+
1621
+                    $relativeMountPoint = substr($mountPoint, $rootLength);
1622
+                    $results = call_user_func_array(array($cache, $method), $args);
1623
+                    if ($results) {
1624
+                        foreach ($results as $result) {
1625
+                            $internalPath = $result['path'];
1626
+                            $result['path'] = rtrim($relativeMountPoint . $result['path'], '/');
1627
+                            $path = rtrim($mountPoint . $internalPath, '/');
1628
+                            $owner = \OC::$server->getUserManager()->get($storage->getOwner($internalPath));
1629
+                            $files[] = new FileInfo($path, $storage, $internalPath, $result, $mount, $owner);
1630
+                        }
1631
+                    }
1632
+                }
1633
+            }
1634
+        }
1635
+        return $files;
1636
+    }
1637
+
1638
+    /**
1639
+     * Get the owner for a file or folder
1640
+     *
1641
+     * @param string $path
1642
+     * @return string the user id of the owner
1643
+     * @throws NotFoundException
1644
+     */
1645
+    public function getOwner($path) {
1646
+        $info = $this->getFileInfo($path);
1647
+        if (!$info) {
1648
+            throw new NotFoundException($path . ' not found while trying to get owner');
1649
+        }
1650
+        return $info->getOwner()->getUID();
1651
+    }
1652
+
1653
+    /**
1654
+     * get the ETag for a file or folder
1655
+     *
1656
+     * @param string $path
1657
+     * @return string
1658
+     */
1659
+    public function getETag($path) {
1660
+        /**
1661
+         * @var Storage\Storage $storage
1662
+         * @var string $internalPath
1663
+         */
1664
+        list($storage, $internalPath) = $this->resolvePath($path);
1665
+        if ($storage) {
1666
+            return $storage->getETag($internalPath);
1667
+        } else {
1668
+            return null;
1669
+        }
1670
+    }
1671
+
1672
+    /**
1673
+     * Get the path of a file by id, relative to the view
1674
+     *
1675
+     * Note that the resulting path is not guarantied to be unique for the id, multiple paths can point to the same file
1676
+     *
1677
+     * @param int $id
1678
+     * @throws NotFoundException
1679
+     * @return string
1680
+     */
1681
+    public function getPath($id) {
1682
+        $id = (int)$id;
1683
+        $manager = Filesystem::getMountManager();
1684
+        $mounts = $manager->findIn($this->fakeRoot);
1685
+        $mounts[] = $manager->find($this->fakeRoot);
1686
+        // reverse the array so we start with the storage this view is in
1687
+        // which is the most likely to contain the file we're looking for
1688
+        $mounts = array_reverse($mounts);
1689
+        foreach ($mounts as $mount) {
1690
+            /**
1691
+             * @var \OC\Files\Mount\MountPoint $mount
1692
+             */
1693
+            if ($mount->getStorage()) {
1694
+                $cache = $mount->getStorage()->getCache();
1695
+                $internalPath = $cache->getPathById($id);
1696
+                if (is_string($internalPath)) {
1697
+                    $fullPath = $mount->getMountPoint() . $internalPath;
1698
+                    if (!is_null($path = $this->getRelativePath($fullPath))) {
1699
+                        return $path;
1700
+                    }
1701
+                }
1702
+            }
1703
+        }
1704
+        throw new NotFoundException(sprintf('File with id "%s" has not been found.', $id));
1705
+    }
1706
+
1707
+    /**
1708
+     * @param string $path
1709
+     * @throws InvalidPathException
1710
+     */
1711
+    private function assertPathLength($path) {
1712
+        $maxLen = min(PHP_MAXPATHLEN, 4000);
1713
+        // Check for the string length - performed using isset() instead of strlen()
1714
+        // because isset() is about 5x-40x faster.
1715
+        if (isset($path[$maxLen])) {
1716
+            $pathLen = strlen($path);
1717
+            throw new \OCP\Files\InvalidPathException("Path length($pathLen) exceeds max path length($maxLen): $path");
1718
+        }
1719
+    }
1720
+
1721
+    /**
1722
+     * check if it is allowed to move a mount point to a given target.
1723
+     * It is not allowed to move a mount point into a different mount point or
1724
+     * into an already shared folder
1725
+     *
1726
+     * @param string $target path
1727
+     * @return boolean
1728
+     */
1729
+    private function isTargetAllowed($target) {
1730
+
1731
+        list($targetStorage, $targetInternalPath) = \OC\Files\Filesystem::resolvePath($target);
1732
+        if (!$targetStorage->instanceOfStorage('\OCP\Files\IHomeStorage')) {
1733
+            \OCP\Util::writeLog('files',
1734
+                'It is not allowed to move one mount point into another one',
1735
+                \OCP\Util::DEBUG);
1736
+            return false;
1737
+        }
1738
+
1739
+        // note: cannot use the view because the target is already locked
1740
+        $fileId = (int)$targetStorage->getCache()->getId($targetInternalPath);
1741
+        if ($fileId === -1) {
1742
+            // target might not exist, need to check parent instead
1743
+            $fileId = (int)$targetStorage->getCache()->getId(dirname($targetInternalPath));
1744
+        }
1745
+
1746
+        // check if any of the parents were shared by the current owner (include collections)
1747
+        $shares = \OCP\Share::getItemShared(
1748
+            'folder',
1749
+            $fileId,
1750
+            \OCP\Share::FORMAT_NONE,
1751
+            null,
1752
+            true
1753
+        );
1754
+
1755
+        if (count($shares) > 0) {
1756
+            \OCP\Util::writeLog('files',
1757
+                'It is not allowed to move one mount point into a shared folder',
1758
+                \OCP\Util::DEBUG);
1759
+            return false;
1760
+        }
1761
+
1762
+        return true;
1763
+    }
1764
+
1765
+    /**
1766
+     * Get a fileinfo object for files that are ignored in the cache (part files)
1767
+     *
1768
+     * @param string $path
1769
+     * @return \OCP\Files\FileInfo
1770
+     */
1771
+    private function getPartFileInfo($path) {
1772
+        $mount = $this->getMount($path);
1773
+        $storage = $mount->getStorage();
1774
+        $internalPath = $mount->getInternalPath($this->getAbsolutePath($path));
1775
+        $owner = \OC::$server->getUserManager()->get($storage->getOwner($internalPath));
1776
+        return new FileInfo(
1777
+            $this->getAbsolutePath($path),
1778
+            $storage,
1779
+            $internalPath,
1780
+            [
1781
+                'fileid' => null,
1782
+                'mimetype' => $storage->getMimeType($internalPath),
1783
+                'name' => basename($path),
1784
+                'etag' => null,
1785
+                'size' => $storage->filesize($internalPath),
1786
+                'mtime' => $storage->filemtime($internalPath),
1787
+                'encrypted' => false,
1788
+                'permissions' => \OCP\Constants::PERMISSION_ALL
1789
+            ],
1790
+            $mount,
1791
+            $owner
1792
+        );
1793
+    }
1794
+
1795
+    /**
1796
+     * @param string $path
1797
+     * @param string $fileName
1798
+     * @throws InvalidPathException
1799
+     */
1800
+    public function verifyPath($path, $fileName) {
1801
+        try {
1802
+            /** @type \OCP\Files\Storage $storage */
1803
+            list($storage, $internalPath) = $this->resolvePath($path);
1804
+            $storage->verifyPath($internalPath, $fileName);
1805
+        } catch (ReservedWordException $ex) {
1806
+            $l = \OC::$server->getL10N('lib');
1807
+            throw new InvalidPathException($l->t('File name is a reserved word'));
1808
+        } catch (InvalidCharacterInPathException $ex) {
1809
+            $l = \OC::$server->getL10N('lib');
1810
+            throw new InvalidPathException($l->t('File name contains at least one invalid character'));
1811
+        } catch (FileNameTooLongException $ex) {
1812
+            $l = \OC::$server->getL10N('lib');
1813
+            throw new InvalidPathException($l->t('File name is too long'));
1814
+        } catch (InvalidDirectoryException $ex) {
1815
+            $l = \OC::$server->getL10N('lib');
1816
+            throw new InvalidPathException($l->t('Dot files are not allowed'));
1817
+        } catch (EmptyFileNameException $ex) {
1818
+            $l = \OC::$server->getL10N('lib');
1819
+            throw new InvalidPathException($l->t('Empty filename is not allowed'));
1820
+        }
1821
+    }
1822
+
1823
+    /**
1824
+     * get all parent folders of $path
1825
+     *
1826
+     * @param string $path
1827
+     * @return string[]
1828
+     */
1829
+    private function getParents($path) {
1830
+        $path = trim($path, '/');
1831
+        if (!$path) {
1832
+            return [];
1833
+        }
1834
+
1835
+        $parts = explode('/', $path);
1836
+
1837
+        // remove the single file
1838
+        array_pop($parts);
1839
+        $result = array('/');
1840
+        $resultPath = '';
1841
+        foreach ($parts as $part) {
1842
+            if ($part) {
1843
+                $resultPath .= '/' . $part;
1844
+                $result[] = $resultPath;
1845
+            }
1846
+        }
1847
+        return $result;
1848
+    }
1849
+
1850
+    /**
1851
+     * Returns the mount point for which to lock
1852
+     *
1853
+     * @param string $absolutePath absolute path
1854
+     * @param bool $useParentMount true to return parent mount instead of whatever
1855
+     * is mounted directly on the given path, false otherwise
1856
+     * @return \OC\Files\Mount\MountPoint mount point for which to apply locks
1857
+     */
1858
+    private function getMountForLock($absolutePath, $useParentMount = false) {
1859
+        $results = [];
1860
+        $mount = Filesystem::getMountManager()->find($absolutePath);
1861
+        if (!$mount) {
1862
+            return $results;
1863
+        }
1864
+
1865
+        if ($useParentMount) {
1866
+            // find out if something is mounted directly on the path
1867
+            $internalPath = $mount->getInternalPath($absolutePath);
1868
+            if ($internalPath === '') {
1869
+                // resolve the parent mount instead
1870
+                $mount = Filesystem::getMountManager()->find(dirname($absolutePath));
1871
+            }
1872
+        }
1873
+
1874
+        return $mount;
1875
+    }
1876
+
1877
+    /**
1878
+     * Lock the given path
1879
+     *
1880
+     * @param string $path the path of the file to lock, relative to the view
1881
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
1882
+     * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage
1883
+     *
1884
+     * @return bool False if the path is excluded from locking, true otherwise
1885
+     * @throws \OCP\Lock\LockedException if the path is already locked
1886
+     */
1887
+    private function lockPath($path, $type, $lockMountPoint = false) {
1888
+        $absolutePath = $this->getAbsolutePath($path);
1889
+        $absolutePath = Filesystem::normalizePath($absolutePath);
1890
+        if (!$this->shouldLockFile($absolutePath)) {
1891
+            return false;
1892
+        }
1893
+
1894
+        $mount = $this->getMountForLock($absolutePath, $lockMountPoint);
1895
+        if ($mount) {
1896
+            try {
1897
+                $storage = $mount->getStorage();
1898
+                if ($storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
1899
+                    $storage->acquireLock(
1900
+                        $mount->getInternalPath($absolutePath),
1901
+                        $type,
1902
+                        $this->lockingProvider
1903
+                    );
1904
+                }
1905
+            } catch (\OCP\Lock\LockedException $e) {
1906
+                // rethrow with the a human-readable path
1907
+                throw new \OCP\Lock\LockedException(
1908
+                    $this->getPathRelativeToFiles($absolutePath),
1909
+                    $e
1910
+                );
1911
+            }
1912
+        }
1913
+
1914
+        return true;
1915
+    }
1916
+
1917
+    /**
1918
+     * Change the lock type
1919
+     *
1920
+     * @param string $path the path of the file to lock, relative to the view
1921
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
1922
+     * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage
1923
+     *
1924
+     * @return bool False if the path is excluded from locking, true otherwise
1925
+     * @throws \OCP\Lock\LockedException if the path is already locked
1926
+     */
1927
+    public function changeLock($path, $type, $lockMountPoint = false) {
1928
+        $path = Filesystem::normalizePath($path);
1929
+        $absolutePath = $this->getAbsolutePath($path);
1930
+        $absolutePath = Filesystem::normalizePath($absolutePath);
1931
+        if (!$this->shouldLockFile($absolutePath)) {
1932
+            return false;
1933
+        }
1934
+
1935
+        $mount = $this->getMountForLock($absolutePath, $lockMountPoint);
1936
+        if ($mount) {
1937
+            try {
1938
+                $storage = $mount->getStorage();
1939
+                if ($storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
1940
+                    $storage->changeLock(
1941
+                        $mount->getInternalPath($absolutePath),
1942
+                        $type,
1943
+                        $this->lockingProvider
1944
+                    );
1945
+                }
1946
+            } catch (\OCP\Lock\LockedException $e) {
1947
+                // rethrow with the a human-readable path
1948
+                throw new \OCP\Lock\LockedException(
1949
+                    $this->getPathRelativeToFiles($absolutePath),
1950
+                    $e
1951
+                );
1952
+            }
1953
+        }
1954
+
1955
+        return true;
1956
+    }
1957
+
1958
+    /**
1959
+     * Unlock the given path
1960
+     *
1961
+     * @param string $path the path of the file to unlock, relative to the view
1962
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
1963
+     * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage
1964
+     *
1965
+     * @return bool False if the path is excluded from locking, true otherwise
1966
+     */
1967
+    private function unlockPath($path, $type, $lockMountPoint = false) {
1968
+        $absolutePath = $this->getAbsolutePath($path);
1969
+        $absolutePath = Filesystem::normalizePath($absolutePath);
1970
+        if (!$this->shouldLockFile($absolutePath)) {
1971
+            return false;
1972
+        }
1973
+
1974
+        $mount = $this->getMountForLock($absolutePath, $lockMountPoint);
1975
+        if ($mount) {
1976
+            $storage = $mount->getStorage();
1977
+            if ($storage && $storage->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) {
1978
+                $storage->releaseLock(
1979
+                    $mount->getInternalPath($absolutePath),
1980
+                    $type,
1981
+                    $this->lockingProvider
1982
+                );
1983
+            }
1984
+        }
1985
+
1986
+        return true;
1987
+    }
1988
+
1989
+    /**
1990
+     * Lock a path and all its parents up to the root of the view
1991
+     *
1992
+     * @param string $path the path of the file to lock relative to the view
1993
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
1994
+     * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage
1995
+     *
1996
+     * @return bool False if the path is excluded from locking, true otherwise
1997
+     */
1998
+    public function lockFile($path, $type, $lockMountPoint = false) {
1999
+        $absolutePath = $this->getAbsolutePath($path);
2000
+        $absolutePath = Filesystem::normalizePath($absolutePath);
2001
+        if (!$this->shouldLockFile($absolutePath)) {
2002
+            return false;
2003
+        }
2004
+
2005
+        $this->lockPath($path, $type, $lockMountPoint);
2006
+
2007
+        $parents = $this->getParents($path);
2008
+        foreach ($parents as $parent) {
2009
+            $this->lockPath($parent, ILockingProvider::LOCK_SHARED);
2010
+        }
2011
+
2012
+        return true;
2013
+    }
2014
+
2015
+    /**
2016
+     * Unlock a path and all its parents up to the root of the view
2017
+     *
2018
+     * @param string $path the path of the file to lock relative to the view
2019
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
2020
+     * @param bool $lockMountPoint true to lock the mount point, false to lock the attached mount/storage
2021
+     *
2022
+     * @return bool False if the path is excluded from locking, true otherwise
2023
+     */
2024
+    public function unlockFile($path, $type, $lockMountPoint = false) {
2025
+        $absolutePath = $this->getAbsolutePath($path);
2026
+        $absolutePath = Filesystem::normalizePath($absolutePath);
2027
+        if (!$this->shouldLockFile($absolutePath)) {
2028
+            return false;
2029
+        }
2030
+
2031
+        $this->unlockPath($path, $type, $lockMountPoint);
2032
+
2033
+        $parents = $this->getParents($path);
2034
+        foreach ($parents as $parent) {
2035
+            $this->unlockPath($parent, ILockingProvider::LOCK_SHARED);
2036
+        }
2037
+
2038
+        return true;
2039
+    }
2040
+
2041
+    /**
2042
+     * Only lock files in data/user/files/
2043
+     *
2044
+     * @param string $path Absolute path to the file/folder we try to (un)lock
2045
+     * @return bool
2046
+     */
2047
+    protected function shouldLockFile($path) {
2048
+        $path = Filesystem::normalizePath($path);
2049
+
2050
+        $pathSegments = explode('/', $path);
2051
+        if (isset($pathSegments[2])) {
2052
+            // E.g.: /username/files/path-to-file
2053
+            return ($pathSegments[2] === 'files') && (count($pathSegments) > 3);
2054
+        }
2055
+
2056
+        return true;
2057
+    }
2058
+
2059
+    /**
2060
+     * Shortens the given absolute path to be relative to
2061
+     * "$user/files".
2062
+     *
2063
+     * @param string $absolutePath absolute path which is under "files"
2064
+     *
2065
+     * @return string path relative to "files" with trimmed slashes or null
2066
+     * if the path was NOT relative to files
2067
+     *
2068
+     * @throws \InvalidArgumentException if the given path was not under "files"
2069
+     * @since 8.1.0
2070
+     */
2071
+    public function getPathRelativeToFiles($absolutePath) {
2072
+        $path = Filesystem::normalizePath($absolutePath);
2073
+        $parts = explode('/', trim($path, '/'), 3);
2074
+        // "$user", "files", "path/to/dir"
2075
+        if (!isset($parts[1]) || $parts[1] !== 'files') {
2076
+            $this->logger->error(
2077
+                '$absolutePath must be relative to "files", value is "%s"',
2078
+                [
2079
+                    $absolutePath
2080
+                ]
2081
+            );
2082
+            throw new \InvalidArgumentException('$absolutePath must be relative to "files"');
2083
+        }
2084
+        if (isset($parts[2])) {
2085
+            return $parts[2];
2086
+        }
2087
+        return '';
2088
+    }
2089
+
2090
+    /**
2091
+     * @param string $filename
2092
+     * @return array
2093
+     * @throws \OC\User\NoUserException
2094
+     * @throws NotFoundException
2095
+     */
2096
+    public function getUidAndFilename($filename) {
2097
+        $info = $this->getFileInfo($filename);
2098
+        if (!$info instanceof \OCP\Files\FileInfo) {
2099
+            throw new NotFoundException($this->getAbsolutePath($filename) . ' not found');
2100
+        }
2101
+        $uid = $info->getOwner()->getUID();
2102
+        if ($uid != \OCP\User::getUser()) {
2103
+            Filesystem::initMountPoints($uid);
2104
+            $ownerView = new View('/' . $uid . '/files');
2105
+            try {
2106
+                $filename = $ownerView->getPath($info['fileid']);
2107
+            } catch (NotFoundException $e) {
2108
+                throw new NotFoundException('File with id ' . $info['fileid'] . ' not found for user ' . $uid);
2109
+            }
2110
+        }
2111
+        return [$uid, $filename];
2112
+    }
2113
+
2114
+    /**
2115
+     * Creates parent non-existing folders
2116
+     *
2117
+     * @param string $filePath
2118
+     * @return bool
2119
+     */
2120
+    private function createParentDirectories($filePath) {
2121
+        $directoryParts = explode('/', $filePath);
2122
+        $directoryParts = array_filter($directoryParts);
2123
+        foreach ($directoryParts as $key => $part) {
2124
+            $currentPathElements = array_slice($directoryParts, 0, $key);
2125
+            $currentPath = '/' . implode('/', $currentPathElements);
2126
+            if ($this->is_file($currentPath)) {
2127
+                return false;
2128
+            }
2129
+            if (!$this->file_exists($currentPath)) {
2130
+                $this->mkdir($currentPath);
2131
+            }
2132
+        }
2133
+
2134
+        return true;
2135
+    }
2136 2136
 }
Please login to merge, or discard this patch.