Overwriting relative symlink leads to undesirable behavior. Consider the following example:
# Create some directories
mkdir test
mkdir test/folder1
mkdir test/folder2
#Create some files
touch test/folder1/file1
touch test/folder1/file2
#Create a relative symlink in folder2 to file1
ln -sr test/folder1/file1 test/folder2/link
#Check the link
ls -l test/folder2/link
# Correctly output a link to ../folder1/file1
#Overwrite the symlink to point to file2
ln -sfr test/folder1/file2 test/folder2/link
#Check the link
ls -l test/folder2/link
# Wrongly output a link to file2 instead of ../folder1/file2
This undesirable behavior is due to a dereferencing of the target when the relative path is computed. Passing CAN_NOLINKS flag to canonicalize_filename_mode solves the problem.