Lazarus and symlinks on linux
Original Reporter info from Mantis: jakub@icewarp.com
-
Reporter name: Jakub Klos
Original Reporter info from Mantis: jakub@icewarp.com
- Reporter name: Jakub Klos
Description:
I have tried to use Lazarus on a symlinked project path. Basically all the project units, includes and everything is symlinked. Since the FPC compiler always uses the physical path Lazarus does the same most of the time.
There are cases when it does not do so and opens the symlink instead (which is wrong due to the fact that FPC compiler always works with physical paths)
- When you open a unit with a Ctrl+mouse click it opens the symlink path and not the physical path. This is caused because the units path in the project use the symlink path and the code below does not handle such scenario. I have patched this and it works properly:
--- sourcefilemanager.pas 2017-01-18 18:15:13.540274783 +0100
+++ sourcefilemanager.pas.new 2017-01-18 18:14:28.000000000 +0100
@@ -1219,7 +1219,8 @@
// check if symlink and ask user if the real file should be opened instead
if FilenameIsAbsolute(FFileName) then begin
s:=CodeToolBoss.GetCompleteSrcPathForDirectory('');
- if SearchDirectoryInSearchPath(s,ExtractFilePath(FFileName))<1 then
+ // Why can symlinks be only outside the searchpath?
+// if SearchDirectoryInSearchPath(s,ExtractFilePath(FFileName))<1 then
begin
// the file is not in the project search path => check if it is a symlink
ChooseSymlink(FFilename,true);
Basically you should not expect that search path cannot contain symlinks.
- The ChooseSymLink function does not work well.
When the prompt dialog opens no matter what you do it always opens the symlink path (even though in the source there is 3 choices but it seems the 3rd one never makes it from the dialog. If you Cancel the dialog, pres Abort or Never it always keeps the symlink.
Like I said in the initial description FPC compiler uses always physical path so it does not even make sense to use the symlink path ever. It should always be converted to physical path.
I made a quick patch to this problem too:
--- dialogprocs.pas 2017-01-18 16:17:13.346915576 +0100
+++ dialogprocs.pas.patch 2017-01-18 15:54:08.000000000 +0100
@@ -520,6 +520,8 @@
// choose physical file
Filename:=TargetFilename;
end else begin
+ FileName := TargetFileName;
+ exit(mrOk);
// ask which filename to use
case IDEQuestionDialog(lisFileIsSymlink,
Format(lisTheFileIsASymlinkOpenInstead,[Filename,LineEnding+LineEnding,TargetFilename]),
So the dialog does not prompt for anything and always uses the physical path.
After these 2 patches Lazarus works 100% in a symlinked environment and mp matter how you open a file it always converts it to physical path which is the correct way.
Steps to reproduce:
-
Prepare the environment
- Physical dir: ~/home/test/physical
- Symlink dir: ~/home/test/symlink -> /users/home/test/physical
- Put testunit.pas to ~/home/test/physical/units/testunit.pas
- Create new project under ~/home/test/physical/projects/test.lpi
- Add project unit path as ~/home/test/symlink/units
- Add to the project's main source the "uses testunit;" -
Issue #1 (closed)
- Now ctrl+mouse click the testunit and it will take you to the symlink path which is wrong -
Issue #2 (closed)
- Close the testunit in the IDE and use the Open dialog Ctrl+O to open the ~/home/test/symlink/units/testunit.pas
It will prompt you whether you want to open the symlink or the physical path but no matter what you do it will always open the symlink path
If you patch the IDE with the patches I provided it will work properly.
You should always check for symlinks (even in the search path) and I think we should not ask if you want to open the symlink file but always open the physical path.
Additional information:
Only related to the IDE and symlinks on Linux
Mantis conversion info:
- Mantis ID: 31260
- Version: 1.6.2
- Monitored by: » jakub@icewarp.com (Jakub Klos)