Passed
Push — master ( 7341d3...08802a )
by Julius
15:04 queued 14s
created
lib/public/Files/Mount/IMountPoint.php 1 patch
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -28,111 +28,111 @@
 block discarded – undo
28 28
  * @since 8.0.0
29 29
  */
30 30
 interface IMountPoint {
31
-	/**
32
-	 * get complete path to the mount point
33
-	 *
34
-	 * @return string
35
-	 * @since 8.0.0
36
-	 */
37
-	public function getMountPoint();
31
+    /**
32
+     * get complete path to the mount point
33
+     *
34
+     * @return string
35
+     * @since 8.0.0
36
+     */
37
+    public function getMountPoint();
38 38
 
39
-	/**
40
-	 * Set the mountpoint
41
-	 *
42
-	 * @param string $mountPoint new mount point
43
-	 * @since 8.0.0
44
-	 */
45
-	public function setMountPoint($mountPoint);
39
+    /**
40
+     * Set the mountpoint
41
+     *
42
+     * @param string $mountPoint new mount point
43
+     * @since 8.0.0
44
+     */
45
+    public function setMountPoint($mountPoint);
46 46
 
47
-	/**
48
-	 * Get the storage that is mounted
49
-	 *
50
-	 * @return \OCP\Files\Storage\IStorage|null
51
-	 * @since 8.0.0
52
-	 */
53
-	public function getStorage();
47
+    /**
48
+     * Get the storage that is mounted
49
+     *
50
+     * @return \OCP\Files\Storage\IStorage|null
51
+     * @since 8.0.0
52
+     */
53
+    public function getStorage();
54 54
 
55
-	/**
56
-	 * Get the id of the storages
57
-	 *
58
-	 * @return string|null
59
-	 * @since 8.0.0
60
-	 */
61
-	public function getStorageId();
55
+    /**
56
+     * Get the id of the storages
57
+     *
58
+     * @return string|null
59
+     * @since 8.0.0
60
+     */
61
+    public function getStorageId();
62 62
 
63
-	/**
64
-	 * Get the id of the storages
65
-	 *
66
-	 * @return int|null
67
-	 * @since 9.1.0
68
-	 */
69
-	public function getNumericStorageId();
63
+    /**
64
+     * Get the id of the storages
65
+     *
66
+     * @return int|null
67
+     * @since 9.1.0
68
+     */
69
+    public function getNumericStorageId();
70 70
 
71
-	/**
72
-	 * Get the path relative to the mountpoint
73
-	 *
74
-	 * @param string $path absolute path to a file or folder
75
-	 * @return string
76
-	 * @since 8.0.0
77
-	 */
78
-	public function getInternalPath($path);
71
+    /**
72
+     * Get the path relative to the mountpoint
73
+     *
74
+     * @param string $path absolute path to a file or folder
75
+     * @return string
76
+     * @since 8.0.0
77
+     */
78
+    public function getInternalPath($path);
79 79
 
80
-	/**
81
-	 * Apply a storage wrapper to the mounted storage
82
-	 *
83
-	 * @param callable $wrapper
84
-	 * @since 8.0.0
85
-	 */
86
-	public function wrapStorage($wrapper);
80
+    /**
81
+     * Apply a storage wrapper to the mounted storage
82
+     *
83
+     * @param callable $wrapper
84
+     * @since 8.0.0
85
+     */
86
+    public function wrapStorage($wrapper);
87 87
 
88
-	/**
89
-	 * Get a mount option
90
-	 *
91
-	 * @param string $name Name of the mount option to get
92
-	 * @param mixed $default Default value for the mount option
93
-	 * @return mixed
94
-	 * @since 8.0.0
95
-	 */
96
-	public function getOption($name, $default);
88
+    /**
89
+     * Get a mount option
90
+     *
91
+     * @param string $name Name of the mount option to get
92
+     * @param mixed $default Default value for the mount option
93
+     * @return mixed
94
+     * @since 8.0.0
95
+     */
96
+    public function getOption($name, $default);
97 97
 
98
-	/**
99
-	 * Get all options for the mount
100
-	 *
101
-	 * @return array
102
-	 * @since 8.1.0
103
-	 */
104
-	public function getOptions();
98
+    /**
99
+     * Get all options for the mount
100
+     *
101
+     * @return array
102
+     * @since 8.1.0
103
+     */
104
+    public function getOptions();
105 105
 
106
-	/**
107
-	 * Get the file id of the root of the storage
108
-	 *
109
-	 * @return int
110
-	 * @since 9.1.0
111
-	 */
112
-	public function getStorageRootId();
106
+    /**
107
+     * Get the file id of the root of the storage
108
+     *
109
+     * @return int
110
+     * @since 9.1.0
111
+     */
112
+    public function getStorageRootId();
113 113
 
114
-	/**
115
-	 * Get the id of the configured mount
116
-	 *
117
-	 * @return int|null mount id or null if not applicable
118
-	 * @since 9.1.0
119
-	 */
120
-	public function getMountId();
114
+    /**
115
+     * Get the id of the configured mount
116
+     *
117
+     * @return int|null mount id or null if not applicable
118
+     * @since 9.1.0
119
+     */
120
+    public function getMountId();
121 121
 
122
-	/**
123
-	 * Get the type of mount point, used to distinguish things like shares and external storage
124
-	 * in the web interface
125
-	 *
126
-	 * @return string
127
-	 * @since 12.0.0
128
-	 */
129
-	public function getMountType();
122
+    /**
123
+     * Get the type of mount point, used to distinguish things like shares and external storage
124
+     * in the web interface
125
+     *
126
+     * @return string
127
+     * @since 12.0.0
128
+     */
129
+    public function getMountType();
130 130
 
131
-	/**
132
-	 * Get the class of the mount provider that this mount originates from
133
-	 *
134
-	 * @return string
135
-	 * @since 24.0.0
136
-	 */
137
-	public function getMountProvider(): string;
131
+    /**
132
+     * Get the class of the mount provider that this mount originates from
133
+     *
134
+     * @return string
135
+     * @since 24.0.0
136
+     */
137
+    public function getMountProvider(): string;
138 138
 }
Please login to merge, or discard this patch.
lib/private/Files/Mount/Manager.php 1 patch
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -38,192 +38,192 @@
 block discarded – undo
38 38
 use OCP\Files\NotFoundException;
39 39
 
40 40
 class Manager implements IMountManager {
41
-	/** @var MountPoint[] */
42
-	private array $mounts = [];
43
-	/** @var CappedMemoryCache<IMountPoint> */
44
-	private CappedMemoryCache $pathCache;
45
-	/** @var CappedMemoryCache<IMountPoint[]> */
46
-	private CappedMemoryCache $inPathCache;
47
-	private SetupManager $setupManager;
48
-
49
-	public function __construct(SetupManagerFactory $setupManagerFactory) {
50
-		$this->pathCache = new CappedMemoryCache();
51
-		$this->inPathCache = new CappedMemoryCache();
52
-		$this->setupManager = $setupManagerFactory->create($this);
53
-	}
54
-
55
-	/**
56
-	 * @param IMountPoint $mount
57
-	 */
58
-	public function addMount(IMountPoint $mount) {
59
-		$this->mounts[$mount->getMountPoint()] = $mount;
60
-		$this->pathCache->clear();
61
-		$this->inPathCache->clear();
62
-	}
63
-
64
-	/**
65
-	 * @param string $mountPoint
66
-	 */
67
-	public function removeMount(string $mountPoint) {
68
-		$mountPoint = Filesystem::normalizePath($mountPoint);
69
-		if (\strlen($mountPoint) > 1) {
70
-			$mountPoint .= '/';
71
-		}
72
-		unset($this->mounts[$mountPoint]);
73
-		$this->pathCache->clear();
74
-		$this->inPathCache->clear();
75
-	}
76
-
77
-	/**
78
-	 * @param string $mountPoint
79
-	 * @param string $target
80
-	 */
81
-	public function moveMount(string $mountPoint, string $target) {
82
-		$this->mounts[$target] = $this->mounts[$mountPoint];
83
-		unset($this->mounts[$mountPoint]);
84
-		$this->pathCache->clear();
85
-		$this->inPathCache->clear();
86
-	}
87
-
88
-	/**
89
-	 * Find the mount for $path
90
-	 *
91
-	 * @param string $path
92
-	 * @return IMountPoint
93
-	 */
94
-	public function find(string $path): IMountPoint {
95
-		$this->setupManager->setupForPath($path);
96
-		$path = Filesystem::normalizePath($path);
97
-
98
-		if (isset($this->pathCache[$path])) {
99
-			return $this->pathCache[$path];
100
-		}
101
-
102
-		$current = $path;
103
-		while (true) {
104
-			$mountPoint = $current . '/';
105
-			if (isset($this->mounts[$mountPoint])) {
106
-				$this->pathCache[$path] = $this->mounts[$mountPoint];
107
-				return $this->mounts[$mountPoint];
108
-			} elseif ($current === '') {
109
-				break;
110
-			}
111
-
112
-			$current = dirname($current);
113
-			if ($current === '.' || $current === '/') {
114
-				$current = '';
115
-			}
116
-		}
117
-
118
-		throw new NotFoundException("No mount for path " . $path . " existing mounts: " . implode(",", array_keys($this->mounts)));
119
-	}
120
-
121
-	/**
122
-	 * Find all mounts in $path
123
-	 *
124
-	 * @param string $path
125
-	 * @return IMountPoint[]
126
-	 */
127
-	public function findIn(string $path): array {
128
-		$this->setupManager->setupForPath($path, true);
129
-		$path = $this->formatPath($path);
130
-
131
-		if (isset($this->inPathCache[$path])) {
132
-			return $this->inPathCache[$path];
133
-		}
134
-
135
-		$result = [];
136
-		$pathLength = \strlen($path);
137
-		$mountPoints = array_keys($this->mounts);
138
-		foreach ($mountPoints as $mountPoint) {
139
-			if (substr($mountPoint, 0, $pathLength) === $path && \strlen($mountPoint) > $pathLength) {
140
-				$result[] = $this->mounts[$mountPoint];
141
-			}
142
-		}
143
-
144
-		$this->inPathCache[$path] = $result;
145
-		return $result;
146
-	}
147
-
148
-	public function clear() {
149
-		$this->mounts = [];
150
-		$this->pathCache->clear();
151
-		$this->inPathCache->clear();
152
-	}
153
-
154
-	/**
155
-	 * Find mounts by storage id
156
-	 *
157
-	 * @param string $id
158
-	 * @return IMountPoint[]
159
-	 */
160
-	public function findByStorageId(string $id): array {
161
-		if (\strlen($id) > 64) {
162
-			$id = md5($id);
163
-		}
164
-		$result = [];
165
-		foreach ($this->mounts as $mount) {
166
-			if ($mount->getStorageId() === $id) {
167
-				$result[] = $mount;
168
-			}
169
-		}
170
-		return $result;
171
-	}
172
-
173
-	/**
174
-	 * @return IMountPoint[]
175
-	 */
176
-	public function getAll(): array {
177
-		return $this->mounts;
178
-	}
179
-
180
-	/**
181
-	 * Find mounts by numeric storage id
182
-	 *
183
-	 * @param int $id
184
-	 * @return IMountPoint[]
185
-	 */
186
-	public function findByNumericId(int $id): array {
187
-		$result = [];
188
-		foreach ($this->mounts as $mount) {
189
-			if ($mount->getNumericStorageId() === $id) {
190
-				$result[] = $mount;
191
-			}
192
-		}
193
-		return $result;
194
-	}
195
-
196
-	/**
197
-	 * @param string $path
198
-	 * @return string
199
-	 */
200
-	private function formatPath(string $path): string {
201
-		$path = Filesystem::normalizePath($path);
202
-		if (\strlen($path) > 1) {
203
-			$path .= '/';
204
-		}
205
-		return $path;
206
-	}
207
-
208
-	public function getSetupManager(): SetupManager {
209
-		return $this->setupManager;
210
-	}
211
-
212
-	/**
213
-	 * Return all mounts in a path from a specific mount provider
214
-	 *
215
-	 * @param string $path
216
-	 * @param string[] $mountProviders
217
-	 * @return MountPoint[]
218
-	 */
219
-	public function getMountsByMountProvider(string $path, array $mountProviders) {
220
-		$this->getSetupManager()->setupForProvider($path, $mountProviders);
221
-		if (in_array('', $mountProviders)) {
222
-			return $this->mounts;
223
-		} else {
224
-			return array_filter($this->mounts, function ($mount) use ($mountProviders) {
225
-				return in_array($mount->getMountProvider(), $mountProviders);
226
-			});
227
-		}
228
-	}
41
+    /** @var MountPoint[] */
42
+    private array $mounts = [];
43
+    /** @var CappedMemoryCache<IMountPoint> */
44
+    private CappedMemoryCache $pathCache;
45
+    /** @var CappedMemoryCache<IMountPoint[]> */
46
+    private CappedMemoryCache $inPathCache;
47
+    private SetupManager $setupManager;
48
+
49
+    public function __construct(SetupManagerFactory $setupManagerFactory) {
50
+        $this->pathCache = new CappedMemoryCache();
51
+        $this->inPathCache = new CappedMemoryCache();
52
+        $this->setupManager = $setupManagerFactory->create($this);
53
+    }
54
+
55
+    /**
56
+     * @param IMountPoint $mount
57
+     */
58
+    public function addMount(IMountPoint $mount) {
59
+        $this->mounts[$mount->getMountPoint()] = $mount;
60
+        $this->pathCache->clear();
61
+        $this->inPathCache->clear();
62
+    }
63
+
64
+    /**
65
+     * @param string $mountPoint
66
+     */
67
+    public function removeMount(string $mountPoint) {
68
+        $mountPoint = Filesystem::normalizePath($mountPoint);
69
+        if (\strlen($mountPoint) > 1) {
70
+            $mountPoint .= '/';
71
+        }
72
+        unset($this->mounts[$mountPoint]);
73
+        $this->pathCache->clear();
74
+        $this->inPathCache->clear();
75
+    }
76
+
77
+    /**
78
+     * @param string $mountPoint
79
+     * @param string $target
80
+     */
81
+    public function moveMount(string $mountPoint, string $target) {
82
+        $this->mounts[$target] = $this->mounts[$mountPoint];
83
+        unset($this->mounts[$mountPoint]);
84
+        $this->pathCache->clear();
85
+        $this->inPathCache->clear();
86
+    }
87
+
88
+    /**
89
+     * Find the mount for $path
90
+     *
91
+     * @param string $path
92
+     * @return IMountPoint
93
+     */
94
+    public function find(string $path): IMountPoint {
95
+        $this->setupManager->setupForPath($path);
96
+        $path = Filesystem::normalizePath($path);
97
+
98
+        if (isset($this->pathCache[$path])) {
99
+            return $this->pathCache[$path];
100
+        }
101
+
102
+        $current = $path;
103
+        while (true) {
104
+            $mountPoint = $current . '/';
105
+            if (isset($this->mounts[$mountPoint])) {
106
+                $this->pathCache[$path] = $this->mounts[$mountPoint];
107
+                return $this->mounts[$mountPoint];
108
+            } elseif ($current === '') {
109
+                break;
110
+            }
111
+
112
+            $current = dirname($current);
113
+            if ($current === '.' || $current === '/') {
114
+                $current = '';
115
+            }
116
+        }
117
+
118
+        throw new NotFoundException("No mount for path " . $path . " existing mounts: " . implode(",", array_keys($this->mounts)));
119
+    }
120
+
121
+    /**
122
+     * Find all mounts in $path
123
+     *
124
+     * @param string $path
125
+     * @return IMountPoint[]
126
+     */
127
+    public function findIn(string $path): array {
128
+        $this->setupManager->setupForPath($path, true);
129
+        $path = $this->formatPath($path);
130
+
131
+        if (isset($this->inPathCache[$path])) {
132
+            return $this->inPathCache[$path];
133
+        }
134
+
135
+        $result = [];
136
+        $pathLength = \strlen($path);
137
+        $mountPoints = array_keys($this->mounts);
138
+        foreach ($mountPoints as $mountPoint) {
139
+            if (substr($mountPoint, 0, $pathLength) === $path && \strlen($mountPoint) > $pathLength) {
140
+                $result[] = $this->mounts[$mountPoint];
141
+            }
142
+        }
143
+
144
+        $this->inPathCache[$path] = $result;
145
+        return $result;
146
+    }
147
+
148
+    public function clear() {
149
+        $this->mounts = [];
150
+        $this->pathCache->clear();
151
+        $this->inPathCache->clear();
152
+    }
153
+
154
+    /**
155
+     * Find mounts by storage id
156
+     *
157
+     * @param string $id
158
+     * @return IMountPoint[]
159
+     */
160
+    public function findByStorageId(string $id): array {
161
+        if (\strlen($id) > 64) {
162
+            $id = md5($id);
163
+        }
164
+        $result = [];
165
+        foreach ($this->mounts as $mount) {
166
+            if ($mount->getStorageId() === $id) {
167
+                $result[] = $mount;
168
+            }
169
+        }
170
+        return $result;
171
+    }
172
+
173
+    /**
174
+     * @return IMountPoint[]
175
+     */
176
+    public function getAll(): array {
177
+        return $this->mounts;
178
+    }
179
+
180
+    /**
181
+     * Find mounts by numeric storage id
182
+     *
183
+     * @param int $id
184
+     * @return IMountPoint[]
185
+     */
186
+    public function findByNumericId(int $id): array {
187
+        $result = [];
188
+        foreach ($this->mounts as $mount) {
189
+            if ($mount->getNumericStorageId() === $id) {
190
+                $result[] = $mount;
191
+            }
192
+        }
193
+        return $result;
194
+    }
195
+
196
+    /**
197
+     * @param string $path
198
+     * @return string
199
+     */
200
+    private function formatPath(string $path): string {
201
+        $path = Filesystem::normalizePath($path);
202
+        if (\strlen($path) > 1) {
203
+            $path .= '/';
204
+        }
205
+        return $path;
206
+    }
207
+
208
+    public function getSetupManager(): SetupManager {
209
+        return $this->setupManager;
210
+    }
211
+
212
+    /**
213
+     * Return all mounts in a path from a specific mount provider
214
+     *
215
+     * @param string $path
216
+     * @param string[] $mountProviders
217
+     * @return MountPoint[]
218
+     */
219
+    public function getMountsByMountProvider(string $path, array $mountProviders) {
220
+        $this->getSetupManager()->setupForProvider($path, $mountProviders);
221
+        if (in_array('', $mountProviders)) {
222
+            return $this->mounts;
223
+        } else {
224
+            return array_filter($this->mounts, function ($mount) use ($mountProviders) {
225
+                return in_array($mount->getMountProvider(), $mountProviders);
226
+            });
227
+        }
228
+    }
229 229
 }
Please login to merge, or discard this patch.
lib/private/Files/Mount/MountPoint.php 1 patch
Indentation   +250 added lines, -250 removed lines patch added patch discarded remove patch
@@ -38,279 +38,279 @@
 block discarded – undo
38 38
 use Psr\Log\LoggerInterface;
39 39
 
40 40
 class MountPoint implements IMountPoint {
41
-	/**
42
-	 * @var \OC\Files\Storage\Storage|null $storage
43
-	 */
44
-	protected $storage = null;
45
-	protected $class;
46
-	protected $storageId;
47
-	protected $numericStorageId = null;
48
-	protected $rootId = null;
41
+    /**
42
+     * @var \OC\Files\Storage\Storage|null $storage
43
+     */
44
+    protected $storage = null;
45
+    protected $class;
46
+    protected $storageId;
47
+    protected $numericStorageId = null;
48
+    protected $rootId = null;
49 49
 
50
-	/**
51
-	 * Configuration options for the storage backend
52
-	 *
53
-	 * @var array
54
-	 */
55
-	protected $arguments = [];
56
-	protected $mountPoint;
50
+    /**
51
+     * Configuration options for the storage backend
52
+     *
53
+     * @var array
54
+     */
55
+    protected $arguments = [];
56
+    protected $mountPoint;
57 57
 
58
-	/**
59
-	 * Mount specific options
60
-	 *
61
-	 * @var array
62
-	 */
63
-	protected $mountOptions = [];
58
+    /**
59
+     * Mount specific options
60
+     *
61
+     * @var array
62
+     */
63
+    protected $mountOptions = [];
64 64
 
65
-	/**
66
-	 * @var \OC\Files\Storage\StorageFactory $loader
67
-	 */
68
-	private $loader;
65
+    /**
66
+     * @var \OC\Files\Storage\StorageFactory $loader
67
+     */
68
+    private $loader;
69 69
 
70
-	/**
71
-	 * Specified whether the storage is invalid after failing to
72
-	 * instantiate it.
73
-	 *
74
-	 * @var bool
75
-	 */
76
-	private $invalidStorage = false;
70
+    /**
71
+     * Specified whether the storage is invalid after failing to
72
+     * instantiate it.
73
+     *
74
+     * @var bool
75
+     */
76
+    private $invalidStorage = false;
77 77
 
78
-	/** @var int|null */
79
-	protected $mountId;
78
+    /** @var int|null */
79
+    protected $mountId;
80 80
 
81
-	/** @var string */
82
-	protected $mountProvider;
81
+    /** @var string */
82
+    protected $mountProvider;
83 83
 
84
-	/**
85
-	 * @param string|\OC\Files\Storage\Storage $storage
86
-	 * @param string $mountpoint
87
-	 * @param array $arguments (optional) configuration for the storage backend
88
-	 * @param \OCP\Files\Storage\IStorageFactory $loader
89
-	 * @param array $mountOptions mount specific options
90
-	 * @param int|null $mountId
91
-	 * @param string|null $mountProvider
92
-	 * @throws \Exception
93
-	 */
94
-	public function __construct(
95
-		$storage,
96
-		string $mountpoint,
97
-		array $arguments = null,
98
-		IStorageFactory $loader = null,
99
-		array $mountOptions = null,
100
-		int $mountId = null,
101
-		string $mountProvider = null
102
-	) {
103
-		if (is_null($arguments)) {
104
-			$arguments = [];
105
-		}
106
-		if (is_null($loader)) {
107
-			$this->loader = new StorageFactory();
108
-		} else {
109
-			$this->loader = $loader;
110
-		}
84
+    /**
85
+     * @param string|\OC\Files\Storage\Storage $storage
86
+     * @param string $mountpoint
87
+     * @param array $arguments (optional) configuration for the storage backend
88
+     * @param \OCP\Files\Storage\IStorageFactory $loader
89
+     * @param array $mountOptions mount specific options
90
+     * @param int|null $mountId
91
+     * @param string|null $mountProvider
92
+     * @throws \Exception
93
+     */
94
+    public function __construct(
95
+        $storage,
96
+        string $mountpoint,
97
+        array $arguments = null,
98
+        IStorageFactory $loader = null,
99
+        array $mountOptions = null,
100
+        int $mountId = null,
101
+        string $mountProvider = null
102
+    ) {
103
+        if (is_null($arguments)) {
104
+            $arguments = [];
105
+        }
106
+        if (is_null($loader)) {
107
+            $this->loader = new StorageFactory();
108
+        } else {
109
+            $this->loader = $loader;
110
+        }
111 111
 
112
-		if (!is_null($mountOptions)) {
113
-			$this->mountOptions = $mountOptions;
114
-		}
112
+        if (!is_null($mountOptions)) {
113
+            $this->mountOptions = $mountOptions;
114
+        }
115 115
 
116
-		$mountpoint = $this->formatPath($mountpoint);
117
-		$this->mountPoint = $mountpoint;
118
-		$this->mountId = $mountId;
119
-		if ($storage instanceof Storage) {
120
-			$this->class = get_class($storage);
121
-			$this->storage = $this->loader->wrap($this, $storage);
122
-		} else {
123
-			// Update old classes to new namespace
124
-			if (strpos($storage, 'OC_Filestorage_') !== false) {
125
-				$storage = '\OC\Files\Storage\\' . substr($storage, 15);
126
-			}
127
-			$this->class = $storage;
128
-			$this->arguments = $arguments;
129
-		}
130
-		if ($mountProvider) {
131
-			if (strlen($mountProvider) > 128) {
132
-				throw new \Exception("Mount provider $mountProvider name exceeds the limit of 128 characters");
133
-			}
134
-		}
135
-		$this->mountProvider = $mountProvider ?? '';
136
-	}
116
+        $mountpoint = $this->formatPath($mountpoint);
117
+        $this->mountPoint = $mountpoint;
118
+        $this->mountId = $mountId;
119
+        if ($storage instanceof Storage) {
120
+            $this->class = get_class($storage);
121
+            $this->storage = $this->loader->wrap($this, $storage);
122
+        } else {
123
+            // Update old classes to new namespace
124
+            if (strpos($storage, 'OC_Filestorage_') !== false) {
125
+                $storage = '\OC\Files\Storage\\' . substr($storage, 15);
126
+            }
127
+            $this->class = $storage;
128
+            $this->arguments = $arguments;
129
+        }
130
+        if ($mountProvider) {
131
+            if (strlen($mountProvider) > 128) {
132
+                throw new \Exception("Mount provider $mountProvider name exceeds the limit of 128 characters");
133
+            }
134
+        }
135
+        $this->mountProvider = $mountProvider ?? '';
136
+    }
137 137
 
138
-	/**
139
-	 * get complete path to the mount point, relative to data/
140
-	 *
141
-	 * @return string
142
-	 */
143
-	public function getMountPoint() {
144
-		return $this->mountPoint;
145
-	}
138
+    /**
139
+     * get complete path to the mount point, relative to data/
140
+     *
141
+     * @return string
142
+     */
143
+    public function getMountPoint() {
144
+        return $this->mountPoint;
145
+    }
146 146
 
147
-	/**
148
-	 * Sets the mount point path, relative to data/
149
-	 *
150
-	 * @param string $mountPoint new mount point
151
-	 */
152
-	public function setMountPoint($mountPoint) {
153
-		$this->mountPoint = $this->formatPath($mountPoint);
154
-	}
147
+    /**
148
+     * Sets the mount point path, relative to data/
149
+     *
150
+     * @param string $mountPoint new mount point
151
+     */
152
+    public function setMountPoint($mountPoint) {
153
+        $this->mountPoint = $this->formatPath($mountPoint);
154
+    }
155 155
 
156
-	/**
157
-	 * create the storage that is mounted
158
-	 */
159
-	private function createStorage() {
160
-		if ($this->invalidStorage) {
161
-			return;
162
-		}
156
+    /**
157
+     * create the storage that is mounted
158
+     */
159
+    private function createStorage() {
160
+        if ($this->invalidStorage) {
161
+            return;
162
+        }
163 163
 
164
-		if (class_exists($this->class)) {
165
-			try {
166
-				$class = $this->class;
167
-				// prevent recursion by setting the storage before applying wrappers
168
-				$this->storage = new $class($this->arguments);
169
-				$this->storage = $this->loader->wrap($this, $this->storage);
170
-			} catch (\Exception $exception) {
171
-				$this->storage = null;
172
-				$this->invalidStorage = true;
173
-				if ($this->mountPoint === '/') {
174
-					// the root storage could not be initialized, show the user!
175
-					throw new \Exception('The root storage could not be initialized. Please contact your local administrator.', $exception->getCode(), $exception);
176
-				} else {
177
-					\OC::$server->get(LoggerInterface::class)->error($exception->getMessage(), ['exception' => $exception]);
178
-				}
179
-				return;
180
-			}
181
-		} else {
182
-			\OC::$server->get(LoggerInterface::class)->error('Storage backend ' . $this->class . ' not found', ['app' => 'core']);
183
-			$this->invalidStorage = true;
184
-			return;
185
-		}
186
-	}
164
+        if (class_exists($this->class)) {
165
+            try {
166
+                $class = $this->class;
167
+                // prevent recursion by setting the storage before applying wrappers
168
+                $this->storage = new $class($this->arguments);
169
+                $this->storage = $this->loader->wrap($this, $this->storage);
170
+            } catch (\Exception $exception) {
171
+                $this->storage = null;
172
+                $this->invalidStorage = true;
173
+                if ($this->mountPoint === '/') {
174
+                    // the root storage could not be initialized, show the user!
175
+                    throw new \Exception('The root storage could not be initialized. Please contact your local administrator.', $exception->getCode(), $exception);
176
+                } else {
177
+                    \OC::$server->get(LoggerInterface::class)->error($exception->getMessage(), ['exception' => $exception]);
178
+                }
179
+                return;
180
+            }
181
+        } else {
182
+            \OC::$server->get(LoggerInterface::class)->error('Storage backend ' . $this->class . ' not found', ['app' => 'core']);
183
+            $this->invalidStorage = true;
184
+            return;
185
+        }
186
+    }
187 187
 
188
-	/**
189
-	 * @return \OC\Files\Storage\Storage|null
190
-	 */
191
-	public function getStorage() {
192
-		if (is_null($this->storage)) {
193
-			$this->createStorage();
194
-		}
195
-		return $this->storage;
196
-	}
188
+    /**
189
+     * @return \OC\Files\Storage\Storage|null
190
+     */
191
+    public function getStorage() {
192
+        if (is_null($this->storage)) {
193
+            $this->createStorage();
194
+        }
195
+        return $this->storage;
196
+    }
197 197
 
198
-	/**
199
-	 * @return string|null
200
-	 */
201
-	public function getStorageId() {
202
-		if (!$this->storageId) {
203
-			$storage = $this->getStorage();
204
-			if (is_null($storage)) {
205
-				return null;
206
-			}
207
-			$this->storageId = $storage->getId();
208
-			if (strlen($this->storageId) > 64) {
209
-				$this->storageId = md5($this->storageId);
210
-			}
211
-		}
212
-		return $this->storageId;
213
-	}
198
+    /**
199
+     * @return string|null
200
+     */
201
+    public function getStorageId() {
202
+        if (!$this->storageId) {
203
+            $storage = $this->getStorage();
204
+            if (is_null($storage)) {
205
+                return null;
206
+            }
207
+            $this->storageId = $storage->getId();
208
+            if (strlen($this->storageId) > 64) {
209
+                $this->storageId = md5($this->storageId);
210
+            }
211
+        }
212
+        return $this->storageId;
213
+    }
214 214
 
215
-	/**
216
-	 * @return int
217
-	 */
218
-	public function getNumericStorageId() {
219
-		if (is_null($this->numericStorageId)) {
220
-			$storage = $this->getStorage();
221
-			if (is_null($storage)) {
222
-				return -1;
223
-			}
224
-			$this->numericStorageId = $storage->getStorageCache()->getNumericId();
225
-		}
226
-		return $this->numericStorageId;
227
-	}
215
+    /**
216
+     * @return int
217
+     */
218
+    public function getNumericStorageId() {
219
+        if (is_null($this->numericStorageId)) {
220
+            $storage = $this->getStorage();
221
+            if (is_null($storage)) {
222
+                return -1;
223
+            }
224
+            $this->numericStorageId = $storage->getStorageCache()->getNumericId();
225
+        }
226
+        return $this->numericStorageId;
227
+    }
228 228
 
229
-	/**
230
-	 * @param string $path
231
-	 * @return string
232
-	 */
233
-	public function getInternalPath($path) {
234
-		$path = Filesystem::normalizePath($path, true, false, true);
235
-		if ($this->mountPoint === $path or $this->mountPoint . '/' === $path) {
236
-			$internalPath = '';
237
-		} else {
238
-			$internalPath = substr($path, strlen($this->mountPoint));
239
-		}
240
-		// substr returns false instead of an empty string, we always want a string
241
-		return (string)$internalPath;
242
-	}
229
+    /**
230
+     * @param string $path
231
+     * @return string
232
+     */
233
+    public function getInternalPath($path) {
234
+        $path = Filesystem::normalizePath($path, true, false, true);
235
+        if ($this->mountPoint === $path or $this->mountPoint . '/' === $path) {
236
+            $internalPath = '';
237
+        } else {
238
+            $internalPath = substr($path, strlen($this->mountPoint));
239
+        }
240
+        // substr returns false instead of an empty string, we always want a string
241
+        return (string)$internalPath;
242
+    }
243 243
 
244
-	/**
245
-	 * @param string $path
246
-	 * @return string
247
-	 */
248
-	private function formatPath($path) {
249
-		$path = Filesystem::normalizePath($path);
250
-		if (strlen($path) > 1) {
251
-			$path .= '/';
252
-		}
253
-		return $path;
254
-	}
244
+    /**
245
+     * @param string $path
246
+     * @return string
247
+     */
248
+    private function formatPath($path) {
249
+        $path = Filesystem::normalizePath($path);
250
+        if (strlen($path) > 1) {
251
+            $path .= '/';
252
+        }
253
+        return $path;
254
+    }
255 255
 
256
-	/**
257
-	 * @param callable $wrapper
258
-	 */
259
-	public function wrapStorage($wrapper) {
260
-		$storage = $this->getStorage();
261
-		// storage can be null if it couldn't be initialized
262
-		if ($storage != null) {
263
-			$this->storage = $wrapper($this->mountPoint, $storage, $this);
264
-		}
265
-	}
256
+    /**
257
+     * @param callable $wrapper
258
+     */
259
+    public function wrapStorage($wrapper) {
260
+        $storage = $this->getStorage();
261
+        // storage can be null if it couldn't be initialized
262
+        if ($storage != null) {
263
+            $this->storage = $wrapper($this->mountPoint, $storage, $this);
264
+        }
265
+    }
266 266
 
267
-	/**
268
-	 * Get a mount option
269
-	 *
270
-	 * @param string $name Name of the mount option to get
271
-	 * @param mixed $default Default value for the mount option
272
-	 * @return mixed
273
-	 */
274
-	public function getOption($name, $default) {
275
-		return isset($this->mountOptions[$name]) ? $this->mountOptions[$name] : $default;
276
-	}
267
+    /**
268
+     * Get a mount option
269
+     *
270
+     * @param string $name Name of the mount option to get
271
+     * @param mixed $default Default value for the mount option
272
+     * @return mixed
273
+     */
274
+    public function getOption($name, $default) {
275
+        return isset($this->mountOptions[$name]) ? $this->mountOptions[$name] : $default;
276
+    }
277 277
 
278
-	/**
279
-	 * Get all options for the mount
280
-	 *
281
-	 * @return array
282
-	 */
283
-	public function getOptions() {
284
-		return $this->mountOptions;
285
-	}
278
+    /**
279
+     * Get all options for the mount
280
+     *
281
+     * @return array
282
+     */
283
+    public function getOptions() {
284
+        return $this->mountOptions;
285
+    }
286 286
 
287
-	/**
288
-	 * Get the file id of the root of the storage
289
-	 *
290
-	 * @return int
291
-	 */
292
-	public function getStorageRootId() {
293
-		if (is_null($this->rootId) || $this->rootId === -1) {
294
-			$storage = $this->getStorage();
295
-			// if we can't create the storage return -1 as root id, this is then handled the same as if the root isn't scanned yet
296
-			if ($storage === null) {
297
-				$this->rootId = -1;
298
-			} else {
299
-				$this->rootId = (int)$storage->getCache()->getId('');
300
-			}
301
-		}
302
-		return $this->rootId;
303
-	}
287
+    /**
288
+     * Get the file id of the root of the storage
289
+     *
290
+     * @return int
291
+     */
292
+    public function getStorageRootId() {
293
+        if (is_null($this->rootId) || $this->rootId === -1) {
294
+            $storage = $this->getStorage();
295
+            // if we can't create the storage return -1 as root id, this is then handled the same as if the root isn't scanned yet
296
+            if ($storage === null) {
297
+                $this->rootId = -1;
298
+            } else {
299
+                $this->rootId = (int)$storage->getCache()->getId('');
300
+            }
301
+        }
302
+        return $this->rootId;
303
+    }
304 304
 
305
-	public function getMountId() {
306
-		return $this->mountId;
307
-	}
305
+    public function getMountId() {
306
+        return $this->mountId;
307
+    }
308 308
 
309
-	public function getMountType() {
310
-		return '';
311
-	}
309
+    public function getMountType() {
310
+        return '';
311
+    }
312 312
 
313
-	public function getMountProvider(): string {
314
-		return $this->mountProvider;
315
-	}
313
+    public function getMountProvider(): string {
314
+        return $this->mountProvider;
315
+    }
316 316
 }
Please login to merge, or discard this patch.