Skip to content

Commit f01c600

Browse files
committed
feature(storage): Add symlink, is_link and readlink to IStorage, Wrapper and Common storage and View
1 parent 0db1a00 commit f01c600

File tree

5 files changed

+93
-7
lines changed

5 files changed

+93
-7
lines changed

lib/private/Files/Storage/Common.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ public function is_file($path) {
121121
return $this->filetype($path) === 'file';
122122
}
123123

124+
public function is_link($path) {
125+
return $this->filetype($path) === 'link';
126+
}
127+
124128
public function filesize($path): false|int|float {
125129
if ($this->is_dir($path)) {
126130
return 0; //by definition

lib/private/Files/Storage/Local.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,17 +326,14 @@ public function file_put_contents($path, $data) {
326326
return $result;
327327
}
328328

329-
/**
330-
* create symlink
331-
*
332-
* @param string $path
333-
* @param string $target
334-
* @return bool
335-
*/
336329
public function symlink($target, $path) {
337330
return symlink($target, $this->getSourcePath($path));
338331
}
339332

333+
public function readlink($path) {
334+
return readlink($this->getSourcePath($path));
335+
}
336+
340337
public function unlink($path) {
341338
if ($this->is_dir($path)) {
342339
return $this->rmdir($path);

lib/private/Files/Storage/Wrapper/Wrapper.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,26 @@ public function opendir($path) {
104104
return $this->getWrapperStorage()->opendir($path);
105105
}
106106

107+
/**
108+
* see https://www.php.net/manual/en/function.symlink.php
109+
*
110+
* @param string $path
111+
* @return string|false
112+
*/
113+
public function symlink($target, $link) {
114+
return $this->getWrapperStorage()->symlink($target, $link);
115+
}
116+
117+
/**
118+
* see https://www.php.net/manual/en/function.readlink.php
119+
*
120+
* @param string $path
121+
* @return string|false
122+
*/
123+
public function readlink($path) {
124+
return $this->getWrapperStorage()->readlink($path);
125+
}
126+
107127
/**
108128
* see https://www.php.net/manual/en/function.is_dir.php
109129
*
@@ -124,6 +144,16 @@ public function is_file($path) {
124144
return $this->getWrapperStorage()->is_file($path);
125145
}
126146

147+
/**
148+
* see https://www.php.net/manual/en/function.is_link.php
149+
*
150+
* @param string $path
151+
* @return bool
152+
*/
153+
public function is_link($path) {
154+
return $this->getWrapperStorage()->is_link($path);
155+
}
156+
127157
/**
128158
* see https://www.php.net/manual/en/function.stat.php
129159
* only the following keys are required in the result: size and mtime

lib/private/Files/View.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,33 @@ public function readfile($path) {
410410
return false;
411411
}
412412

413+
/**
414+
* Return symlink target of given symlink
415+
*
416+
* @param string $path
417+
* @return mixed
418+
* @throws LockedException
419+
* @throws InvalidPathException
420+
*/
421+
public function readlink($path) {
422+
$this->assertPathLength($path);
423+
return $this->basicOperation('readlink', $path, ['read']);
424+
}
425+
426+
/**
427+
* Create symlink at given path to the specified target
428+
*
429+
* @param string $target
430+
* @param string $path
431+
* @return mixed
432+
* @throws LockedException
433+
* @throws InvalidPathException
434+
*/
435+
public function symlink($target, $path) {
436+
$this->assertPathLength($path);
437+
return $this->basicOperation('symlink', $path, ['create', 'write'], $target);
438+
}
439+
413440
/**
414441
* @param string $path
415442
* @param int $from

lib/public/Files/Storage/IStorage.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ public function is_dir($path);
108108
*/
109109
public function is_file($path);
110110

111+
/**
112+
* see https://www.php.net/manual/en/function.is-link.php
113+
*
114+
* @param string $path
115+
* @return bool
116+
* @since TODO
117+
*/
118+
public function is_link($path);
119+
111120
/**
112121
* see https://www.php.net/manual/en/function.stat.php
113122
* only the following keys are required in the result: size and mtime
@@ -238,6 +247,25 @@ public function file_put_contents($path, $data);
238247
*/
239248
public function unlink($path);
240249

250+
/**
251+
* see https://www.php.net/manual/en/function.symlink.php
252+
*
253+
* @param string $target
254+
* @param string $link
255+
* @return bool
256+
* @since TODO
257+
*/
258+
public function symlink($target, $link);
259+
260+
/**
261+
* see https://www.php.net/manual/en/function.readlink.php
262+
*
263+
* @param string $path
264+
* @return string|false
265+
* @since TODO
266+
*/
267+
public function readlink($path);
268+
241269
/**
242270
* see https://www.php.net/manual/en/function.rename.php
243271
*

0 commit comments

Comments
 (0)