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

Breadcrumb

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

function Filesystem::isJunction

Returns whether the target directory is a Windows NTFS Junction.

We test if the path is a directory and not an ordinary link, then check that the mode value returned from lstat (which gives the status of the link itself) is not a directory, by replicating the POSIX S_ISDIR test.

This logic works because PHP does not set the mode value for a junction, since there is no universal file type flag for it. Unfortunately an uninitialized variable in PHP prior to 7.2.16 and 7.3.3 may cause a random value to be returned. See https://bugs.php.net/bug.php?id=77552

If this random value passes the S_ISDIR test, then a junction will not be detected and a recursive delete operation could lead to loss of data in the target directory. Note that Windows rmdir can handle this situation and will only delete the junction (from Windows 7 onwards).

Parameters

string $junction Path to check.:

Return value

bool

3 calls to Filesystem::isJunction()
Filesystem::junction in vendor/composer/composer/src/Composer/Util/Filesystem.php
Creates an NTFS junction.
Filesystem::removeEdgeCases in vendor/composer/composer/src/Composer/Util/Filesystem.php
Filesystem::removeJunction in vendor/composer/composer/src/Composer/Util/Filesystem.php
Removes a Windows NTFS junction.

File

vendor/composer/composer/src/Composer/Util/Filesystem.php, line 869

Class

Filesystem
@author Jordi Boggiano <j.boggiano@seld.be> @author Johannes M. Schmitt <schmittjoh@gmail.com>

Namespace

Composer\Util

Code

public function isJunction(string $junction) {
    if (!Platform::isWindows()) {
        return false;
    }
    // Important to clear all caches first
    clearstatcache(true, $junction);
    if (!is_dir($junction) || is_link($junction)) {
        return false;
    }
    $stat = lstat($junction);
    // S_ISDIR test (S_IFDIR is 0x4000, S_IFMT is 0xF000 bitmask)
    return is_array($stat) ? 0x4000 !== ($stat['mode'] & 0xf000) : false;
}

API Navigation

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