Bug 343125

Summary: Project view doesn't reflect changes in directory structure after switching branch
Product: [Developer tools] kdevplatform Reporter: Piotr Mierzwinski <piotr.mierzwinski>
Component: projectAssignee: kdevelop-bugs-null
Status: CONFIRMED ---    
Severity: normal CC: eugene.shalygin+bugzilla.kde, nhaehnle, piotr.mierzwinski
Priority: NOR    
Version First Reported In: 1.7.0   
Target Milestone: ---   
Platform: Mageia RPMs   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Piotr Mierzwinski 2015-01-21 16:54:08 UTC
Git as System Control Version.
After switching branch (outside of the KDevelop) to another with little different directory structure "Project view" doesn't reflect these changes. After use "Reload" on top of the tree  (from popup menu) doesn't bring result at all. Almost nothing changes. Only branch name is updated on top of the tree. In file system seems to be all OK (git did their job). I can see old and new directories.

Reproducible: Always

Steps to Reproduce:
1. Create project with directory structure similar to below (in master branch):
ProjectNane (master)
 |- MainSubdirectory
 |- Subdirectory_1
 |   \-file1
 \- Subdirectory_2
     \-file2

2. Commit all changes. 
3. Create new branch: "new_branch" and switch to it (in terminal outside of KDevelop).
4. Change (in terminal outside of KDevelop) directory structure in way similar to below:
ProjectNane (new_branch)
 \- MainSubdirectory
    |- Subdirectory_1
    |   \-file1
    \- Subdirectory_2
        \-file2
As you can see Subdirectory_1 and Subdirectory_2 have been moved to MainSubdirectory. This is only one change,

5. Commit all changes. 
6. Run "git branch master" from terminal (outside of the KDevelop).
7. Check Project view

Actual Results:  
Directory structure in Project view didn't change.
I can see directory structure from point 1.
Restart of KDevelop helps. I mean directory structure looks like these from file system.

Expected Results:  
Directory structure in Project view reflects the changes in file system.
Would be nice to have directory structure from point 4, so up-to-dated.
Comment 1 Piotr Mierzwinski 2015-01-22 00:18:58 UTC
I've repeated above scenario on freshly running KDevelop and (un)fortunately it didn't happen. I mean Project view correctly reflected directory structure.
I'm not sure, but maybe opened files from other branch (not existing in first one) were blocking something to KDevelope (or some part of kdevplatform) was able correctly prepare tree in Project view. Anyway this is not reproducible in every time.
Comment 2 Piotr Mierzwinski 2015-01-22 00:40:48 UTC
Ehh. One more test showed that actually this is repeatable. Just I've done more one tine "git co new_branch" (from external terminal) and unfortunately Project view has not been updated properly. I can add only that mentioned main directory ("MainSubdirectory") was expanded in tree in the moment of changing the branch. I'm waiting on somebody who could confirm this behavior.
Comment 3 Nicolai Hähnle 2015-01-22 07:35:11 UTC
Dear Piotr, thank you for following up on this. I can confirm that this also happens in the KF5-based master, and I can tell you that this is a problem already known to others as well, though it would still be nice to have a rock-solid set of reproduction steps.

This issue can be quite grating and should really be fixed. Unfortunately, it just seems that nobody has yet had the time to really look into it. KDevelop as a project doesn't have that many volunteers, let alone funding.
Comment 4 Milian Wolff 2015-01-22 12:03:53 UTC
On the CLI, did you by any chance see warning messages like "too many open files" or the like? Sadly, the kernel only offers extremely limited API to watch deep file trees recursively and then one easily hits such limits. Once the limit is reached, no watchers are added and we end up with situations like this.

Of course, it could also be another bug on top of the above, unrelated to that. But looking at the CLI output would definitely help here.
Comment 5 Piotr Mierzwinski 2015-01-22 14:12:05 UTC
@Milian Wolff
I don't remember any messages about "too many open files" or the like. In moment of test I had set limit on 1024 files. Now I increased it to 2048.  Files tree, tested by me wasn't so deep (2 levels starting from root dir of project), so I don't understand your concerns about watching deep file trees.

I did another test on other project. I've run KDevelop in terminal (konsole). I had opened a lot of files in my project (more than 20). I've switched branch. The result was following. Already opened files changed their status - need to reload. Unfortunately in the "Project view" noting happened :(. In file system I can see different directories than in "Project view". Below you can find result what KDevelop returned (during this operation) in terminal (maybe will be helpful, and maybe you know similar).
There wasn't any "too many open files" message in terminal, only:
<code>
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
</code>

Output from KDevelop (I've cut not interesting rows):
<code>
uint DBusMenuExporterDBus::GetLayout(int, int, const QStringList&, DBusMenuLayoutItem&): Condition failed: menu 
kdevelop(6252)/kdevplatform (shell) KDevelop::RunController::registerJob: non-killable job CMakeImportJob(0x940ff08) registered - this might lead to crashes on shutdown. 
QInotifyFileSystemWatcherEngine::addPaths: inotify_add_watch failed: Nie ma takiego pliku ani katalogu
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/plugins/vfs/ftpsubsystem
kdevelop(6252)/kdevplatform (shell) KDevelop::RunController::registerJob: non-killable job CMakeImportJob(0xa824550) registered - this might lead to crashes on shutdown. 
QFileSystemWatcher: failed to add paths: /usr/share/cmake/Modules/CMakeUnixFindMake.cmake
QFileSystemWatcher: failed to add paths: /usr/share/cmake/Modules/CMakeDetermineSystem.cmake
QFileSystemWatcher: failed to add paths: /usr/share/cmake/Modules/CMakeSystemSpecificInformation.cmake
QFileSystemWatcher: failed to add paths: /usr/share/cmake/Modules/CMakeDetermineCCompiler.cmake
QFileSystemWatcher: failed to add paths: /usr/share/cmake/Modules/CMakeDetermineCXXCompiler.cmake
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/src/CMakeLists.txt
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/xdgmime/CMakeLists.txt
QProcess: Destroyed while process is still running.
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/src
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/xdgmime
QProcess: Destroyed while process is still running.
</code>

QFileSystemWatcher returned error "failed to add paths". The most likely some limit was running out. If yes, then is there any workaround on this? I mean doing job on installments refreshing directory structure in "Project view". Something like this: 
1. apply changes before limit reaching and save the point where watching stopped (I suppose we know the limit if not then first error is a marker)
2. destroy watching object
3. create watching object (now we will have new limit)
4. start watching from saved point
5. go to 1

"qtcmd2" is main directory of project.
The changes were in directory plugins which one is placed on the same level like src.
Message: "Nie ma takiego pliku ani katalogu" means in english: "There is no such file nor directory".
I suppose "inotify_add_watch failed:" message is coming from kernel.
Comment 6 Milian Wolff 2015-01-22 14:42:16 UTC
QInotifyFileSystemWatcherEngine::addPaths: inotify_add_watch failed: Nie ma
takiego pliku ani katalogu

^-- this might also indicate an error, but a different one.

Later on:
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/src/CMakeLists.txt

this I think is exactly the issue I'm talking about. The problem is that the limit of, in your case 2048 files, is *global*. So even if you only have a small project in KDevelop, it fails if many other apps in the background also setup listeners. We really need something better here. The only "fix" I see is increasing your file limit, to a **large** number (such as 65536 or more).

Otherwise, does "reload" help? Via the context menu on the project root?
Comment 7 Piotr Mierzwinski 2015-01-23 01:18:04 UTC
As far as I remember "Reload" didn't help in that case.

I was increasing the limit opened files to 65536 and it seems that works :). Even despite the errors spitted by QFileSystemWatcher - below you can find result from switching some branch to master and one the other way round. I didn't try with other number.
It's working, but the problem is that default limit in most of Linux distribution set on value much lower. I suppose you are aware of this. In my distribution this is 1024. And with this value it doesn't work properly. 
I think this can't be final solution. Of course you can public such solution in KDevelop web site and put notes that this is temporary solution.
And one more thing. I've restored limit to 2048 and did the test again. Surprisingly it worked this time. KDevelop was running in the moment of decreasing the limit. After restart of KDevelop still works, didn't check what will be after restart of OS. It's little wired, because before it doesn't work with such limit :/.

git co new_branch
<code>
uint DBusMenuExporterDBus::GetLayout(int, int, const QStringList&, DBusMenuLayoutItem&): Condition failed: menu 
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/plugins/vfs
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/src/vfs
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/src/ui
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/src
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/plugins
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/plugins/vfs/tarsubsystem
kdevelop(9505)/kdevplatform (shell) KDevelop::RunController::registerJob: non-killable job CMakeImportJob(0x9b26f38) registered - this might lead to crashes on shutdown. 
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/src
Detaching after fork from child process 19854.
Detaching after fork from child process 19855.
Detaching after fork from child process 19856.
Detaching after fork from child process 19857.
Detaching after fork from child process 19858.
Detaching after fork from child process 19859.
QProcess: Destroyed while process is still running.
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/src/vfs
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/src/ui
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/src
Detaching after fork from child process 19865.
</code>

git co master
<code>
uint DBusMenuExporterDBus::GetLayout(int, int, const QStringList&, DBusMenuLayoutItem&): Condition failed: menu 
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/plugins/vfs
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/src/vfs
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/src/ui
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/src
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/plugins
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/plugins/vfs/tarsubsystem
kdevelop(9505)/kdevplatform (shell) KDevelop::RunController::registerJob: non-killable job CMakeImportJob(0x9b26f38) registered - this might lead to crashes on shutdown. 
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/src
Detaching after fork from child process 19854.
Detaching after fork from child process 19855.
Detaching after fork from child process 19856.
Detaching after fork from child process 19857.
Detaching after fork from child process 19858.
Detaching after fork from child process 19859.
QProcess: Destroyed while process is still running.
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/src/vfs
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/src/ui
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/src
Detaching after fork from child process 19865.
[Thread 0x982d2b40 (LWP 19851) exited]
kdevelop(9505)/kdevplatform (shell) KDevelop::RunController::registerJob: non-killable job CMakeImportJob(0xaba9428) registered - this might lead to crashes on shutdown. 
[New Thread 0x982d2b40 (LWP 20000)]
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/src
Detaching after fork from child process 20001.
Detaching after fork from child process 20002.
Detaching after fork from child process 20006.
Detaching after fork from child process 20007.
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/plugins/vfs
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/src/vfs
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/src/ui
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/src
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/plugins
QFileSystemWatcher: failed to add paths: /home/piotr/Projekty/Qt/qtcmd_work/qtcmd_git/qtcmd2/plugins/vfs/tarsubsystem
Detaching after fork from child process 20013.
</code>