New in Symfony 3.2: Filesystem improvements
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
The Filesystem component is a small package that provides convenient utilities for common file system operations. It also abstracts the different behavior of operating systems for some of those file system functions.
In Symfony 3.2 we improved it adding two new functions.
readlink() function returns the target of a symbolic link. However,
its behavior is completely different under Windows and Unix. On Windows systems,
readlink() resolves recursively the children links of a link until a final
target is found. On Unix-based systems
readlink() only resolves the next link.
readlink() provided by the Filesystem component always behaves in
the same way:
public function readlink($path, $canonicalize = false)
$pathdoes not exist or is not a link, it returns
$pathis a link, it returns the next direct target of the link without considering the existence of the target.
$pathdoes not exist, it returns
$pathexists, it returns its absolute fully resolved final version.
Although most of the times developers use soft or symbolic links, sometimes it's convenient to create "hard links". The behavior of hard links is similar to the way object references work: a hard link points to the exact same inode of the target file and you can even rename the target file without breaking the hard link.
hardlink() method of the Filesystem component lets you create single
or multiple hard links to a given file:
1 2 3 4 5 6 7 8
use Symfony\Component\Filesystem\Filesystem; $fs = new Filesystem(); $fs->hardlink('file1.txt', 'hardlink1.lnk'); // fileinode('file1.txt') === fileinode('hardlink1.lnk') // multiple hardlinks pointing to the same file $fs->hardlink('file2.txt', ['hardlink2.lnk', 'hardlink3.lnk']);
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.