function Filesystem::hardlink
Creates a hard link, or several hard links to a file.
Parameters
string|string[] $targetFiles The target file(s):
Throws
FileNotFoundException When original file is missing or not a file
IOException When link fails, including if link already exists
File
-
vendor/
symfony/ filesystem/ Filesystem.php, line 366
Class
- Filesystem
- Provides basic utility to manipulate the file system.
Namespace
Symfony\Component\FilesystemCode
public function hardlink(string $originFile, string|iterable $targetFiles) : void {
self::assertFunctionExists('link');
if (!$this->exists($originFile)) {
throw new FileNotFoundException(null, 0, null, $originFile);
}
if (!is_file($originFile)) {
throw new FileNotFoundException(\sprintf('Origin file "%s" is not a file.', $originFile));
}
foreach ($this->toIterable($targetFiles) as $targetFile) {
if (is_file($targetFile)) {
if (fileinode($originFile) === fileinode($targetFile)) {
continue;
}
$this->remove($targetFile);
}
if (!self::box('link', $originFile, $targetFile)) {
$this->linkException($originFile, $targetFile, 'hard');
}
}
}