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