Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Filesystem.php

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\Filesystem

Code

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');
        }
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal