Create symbolic or hard link to file.

\public
\static
350162
function fileLinkCopy( $srcPath, $dstPath, $symLink )
    {
        eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fileLinkCopy( '$srcPath', '$dstPath' )", __METHOD__ );

        eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
        eZFileHandler::linkCopy( $srcPath, $dstPath, $symLink );
        eZDebug::accumulatorStop( 'dbfile' );
    }
29787
public static function createSymbolicLink($rootDir = null)
    {
        $isCli = Request::isCli();

        is_null($rootDir) && $rootDir = CML_PROJECT_PATH . DIRECTORY_SEPARATOR . 'public';
        is_dir($rootDir) || mkdir($rootDir, true, 0700);

        if ($isCli) {
            Output::writeln(Colour::colour('create link start!', [Colour::GREEN, Colour::HIGHLIGHT]));

            Output::writeln(Colour::colour("  ROOT DIR >>>> {$rootDir}", [Colour::WHITE]));
        } else {
            echo "<br />**************************create link start!*********************<br />";
            echo "  ROOT DIR >>>> {$rootDir} <br />";
        }
        //modules_static_path_name
        // 递归遍历目录

        $createDirFunc = function ($distDir, $resourceDir, $fileName) use ($isCli) {
            $cmd = Request::operatingSystem() ? "rd /Q {$distDir}" : "rm -rf {$distDir}";
            exec($cmd);
            $cmd = Request::operatingSystem() ? "mklink /d {$distDir} {$resourceDir}" : "ln -s {$resourceDir} {$distDir}";
            is_dir($distDir) || exec($cmd, $result);
            $tip = "  create link Application [{$fileName}] result : ["
                . (is_dir($distDir) ? 'true' : 'false') . "]";
            if ($isCli) {
                Output::writeln(Colour::colour($tip, [Colour::WHITE, Colour::HIGHLIGHT]));
            } else {
                print_r('|<span style="color:blue">' . str_pad($tip, 64, ' ', STR_PAD_BOTH) . '</span>|');
            }
        };

        //创建系统静态文件目录映射
        /* $createDirFunc(
             $rootDir . DIRECTORY_SEPARATOR . 'cmlphpstatic',
             __DIR__ . DIRECTORY_SEPARATOR . 'Static',
             'cmlphpstatic'
         );*/

        $dirIteratorFunc = function ($dir, $parentDirName = '') use ($rootDir, $createDirFunc, &$dirIteratorFunc) {
            $dirIterator = new \DirectoryIterator($dir);

            foreach ($dirIterator as $file) {
                if (!$file->isDot() && $file->isDir()) {
                    $resourceDir = $file->getPathname() . DIRECTORY_SEPARATOR . Cml::getApplicationDir('app_static_path_name');

                    $currentDirName = ltrim($parentDirName, DIRECTORY_SEPARATOR);
                    $currentDirName .= ($currentDirName ? DIRECTORY_SEPARATOR : '') . $file->getFilename();

                    if (is_dir($resourceDir)) {
                        if ($file->getFilename() != $currentDirName) {
                            $parentDir = trim(substr($currentDirName, 0, strpos($currentDirName, $file->getFilename())), DIRECTORY_SEPARATOR);
                            is_dir($rootDir . DIRECTORY_SEPARATOR . $parentDir) || mkdir($rootDir . DIRECTORY_SEPARATOR . $parentDir, 0700, true);
                        }
                        $distDir = $rootDir . DIRECTORY_SEPARATOR . $currentDirName;
                        $createDirFunc($distDir, $resourceDir, $currentDirName);
                    } /*else if (!is_dir($file->getPathname() . DIRECTORY_SEPARATOR . Cml::getApplicationDir('app_controller_path_name'))) {
                        $dirIteratorFunc($file->getPathname(), $currentDirName);
                    }*/
                    $dirIteratorFunc($file->getPathname(), $currentDirName);//找到resource了还是继续迭代子目录
                }
            }
        };

        $dirIteratorFunc(Cml::getApplicationDir('apps_path'));

        if ($isCli) {
            Output::writeln(Colour::colour('create link end!', [Colour::GREEN, Colour::HIGHLIGHT]));
        } else {
            echo("<br />****************************create link end!**********************<br />");
        }
    }
142154
function link($target, $link)
    {
        $this->files->ensureDirExists(
            $linkPath = $this->sitesPath(), user()
        );

        $this->config->prependPath($linkPath);

        $this->files->symlinkAsUser($target, $linkPath.'/'.$link);

        return $linkPath.'/'.$link;
    }
1287650
private static function links()
    {
        $files = ['Link'];
        $folder = static::$root.'Http/Links'.'/';

        self::call($files, $folder);

        $files = ['LinkKeyNotFoundException'];
        $folder = static::$root.'Http/Links/Exceptions'.'/';

        self::call($files, $folder);
    }
1292084
def make_links(self):
        
        for dep in self.deps:
            filepaths, exts = dep.get_filepaths_and_exts()

            for path, ext in zip(filepaths, exts):
                logger.info("Need path %s with ext %s" % (path, ext))
                dest = self.ipath_from_ext(ext)

                if not os.path.exists(path):
                    # Try netcdf file.
                    # TODO: this case should be treated in a cleaner way.
                    path += ".nc"
                    if os.path.exists(path): dest += ".nc"

                if not os.path.exists(path):
                    raise self.Error("%s: %s is needed by this task but it does not exist" % (self, path))

                if path.endswith(".nc") and not dest.endswith(".nc"): # NC --> NC file
                    dest += ".nc"

                # Link path to dest if dest link does not exist.
                # else check that it points to the expected file.
                logger.debug("Linking path %s --> %s" % (path, dest))
                if not os.path.exists(dest):
                    os.symlink(path, dest)
                else:
                    # check links but only if we haven't performed the restart.
                    # in this case, indeed we may have replaced the file pointer with the
                    # previous output file of the present task.
                    if os.path.realpath(dest) != path and self.num_restarts == 0:
                        raise self.Error("\nDestination:\n %s\ndoes not point to path:\n %s" % (dest, path))
662973
function fileLinkCopy( $srcPath, $dstPath, $symLink )
    {
        $srcPath = self::cleanPath( $srcPath );
        $dstPath = self::cleanPath( $dstPath );
        eZDebugSetting::writeDebug( 'kernel-clustering', "dfs::fileLinkCopy( '$srcPath', '$dstPath' )" );

        self::$dbbackend->_linkCopy( $srcPath, $dstPath );
    }
272232
def static_url(redis, path):
    """"""
    file_hash = get_cache_buster(redis, path)
    return "%s/%s?v=%s" % (oz.settings["static_host"], path, file_hash)
1127797
private function createStatic()
    {
        // 主题里面的静态文件
        $files = $this->fileSys->getFiles($this->themes_dir . DIRECTORY_SEPARATOR . 'static');
        // 文件拷贝
        array_walk($files, function ($file)
        {
            $search_str = $this->themes_dir . DIRECTORY_SEPARATOR . 'static';
            $replace_str = $this->public_dir . DIRECTORY_SEPARATOR . 'static';
            $to_path = str_replace($search_str, $replace_str, $file['file_path']);
            $this->fileSys->copy($file['file_path'], $to_path);
        });
    }
1279852
public SymbolicLink createSymbolicLink(
      JimfsPath path, JimfsPath target, FileAttribute<?>... attrs) throws IOException {
    if (!store.supportsFeature(Feature.SYMBOLIC_LINKS)) {
      throw new UnsupportedOperationException();
    }
    return (SymbolicLink) createFile(path, store.symbolicLinkCreator(target), true, attrs);
  }
288050
public static function ini()
    {
        $files = glob(static::path().'*.php');

        foreach ($files as $file) {
            $table = need($file);

            foreach ($table as $key => $value) {
                $file = static::getFileName($file);

                self::$links[$file][$key] = $value;
            }
        }
    }
245097
def atomic_symlink(src, dst):
    """"""

    dst_dir = os.path.dirname(dst)
    tmp = None
    max_tries = getattr(os, 'TMP_MAX', 10000)

    try:
        if not os.path.exists(dst_dir):
            os.makedirs(dst_dir)
        for n in range(max_tries):
            try:
                # mktemp is described as being unsafe. That is not true in this case since symlink is an
                # atomic operation at the file system level; if some other processes creates a file with
                # 'our' name then symlink will fail.
                tmp = tempfile.mktemp(dir=dst_dir)
                os.symlink(src, tmp)
                logger.debug('created symlink %s', tmp)
            except OSError as e:
                if e.errno == errno.EEXIST:
                    continue  # Someone else grabbed the temporary name first
                else:
                    raise
            logger.debug('renaming %s to %s', tmp, dst)
            os.rename(tmp, dst)
            return
    except:
        if tmp and os.path.exists(tmp):
            os.remove(tmp)
        raise
    raise IOError(errno.EEXIST, 'No usable temporary file name found')
1124219
public function createLink($from, $to)
    {
        if (File::exists($from)) {
            if (!File::exists($to)) {
                try {
                    symlink($from, $to);
                } catch (\Exception $e) {
                    throw new \Exception("Cannot create symlink from $from to $to");
                }
            }
        }
    }
832048
static function file(string $file, ?int $activeLine = null, ?array $lineRange = null, ?string $className = null): string
    {
        return static::process((string) @highlight_file($file, true), $activeLine, $lineRange, $className);
    }
548982
def link(src, path):
    '''
    
    '''
    src = os.path.expanduser(src)

    if not os.path.isabs(src):
        raise SaltInvocationError('File path must be absolute.')

    try:
        os.link(src, path)
        return True
    except (OSError, IOError):
        raise CommandExecutionError('Could not create \'{0}\''.format(path))
    return False
743358
public static function public_path(?string $file = null)
  {
    $file = (substr($file, 0, 1) == DIRECTORY_SEPARATOR ? substr($file, 1) : $file);
    return config('app.dir') . 'storage' . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . $file;
  }
501057
protected function createAttachmentLink(File $file, AttachableObjectInterface $object, $fieldName, Attachment $attachment, $customFilename = null)
    {
        if ($file instanceof UploadedFile)
        {
            $extension = $file->getClientOriginalExtension();
            $filename = $file->getClientOriginalName();
            $basename = basename($filename, '.'.$extension);
        }
        else
        {
            $extension = $file->getExtension();
            $filename = $file->getFilename();
            $basename = $file->getBasename('.'.$extension);
        }
        
        if (null !== $customFilename)
        {
            $filename = $customFilename;
            $basename = basename($filename, '.'.$extension);
        }
        
        $link = new AttachmentLink();
        $link
            ->setAttachment($attachment)
            ->setModelName($object->getAttachableClassName())
            ->setModelId($object->getAttachableId())
            ->setModelField($fieldName)
            ->setFileName($filename)
            ->setFileExtension($extension)
            ->setCustomName($basename)
        ;
        
        return $link;
    }
180433
def interlink_static_files(generator):
    ''''''
    if generator.settings['STATIC_PATHS'] != []:
        return                               # customized STATIC_PATHS
    try: # minimize attr lookup
        static_content = generator.context['static_content']
    except KeyError:
        static_content = generator.context['filenames']
    relpath = relpath_to_site(generator.settings['DEFAULT_LANG'], _MAIN_LANG)
    for staticfile in _MAIN_STATIC_FILES:
        if staticfile.get_relative_source_path() not in static_content:
            staticfile = copy(staticfile) # prevent override in main site
            staticfile.override_url = posixpath.join(relpath, staticfile.url)
            try:
                generator.add_source_path(staticfile, static=True)
            except TypeError:
                generator.add_source_path(staticfile)