Bug 227156 - New tabs are sometime opened in a wrong directory
Summary: New tabs are sometime opened in a wrong directory
Status: RESOLVED FIXED
Alias: None
Product: konsole
Classification: Applications
Component: general (show other bugs)
Version: 2.4
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Konsole Developer
URL:
Keywords:
: 189528 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-02-16 10:54 UTC by Sylvain HENRY
Modified: 2011-04-10 22:49 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In: 4.7


Attachments
Proposed patch (641 bytes, patch)
2010-02-19 00:54 UTC, Christoph Feck
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sylvain HENRY 2010-02-16 10:54:20 UTC
Version:           2.4 (using 4.4.00 (KDE 4.4.0), Arch Linux)
Compiler:          gcc
OS:                Linux (x86_64) release 2.6.32-ARCH

When a new tab is opened in Konsole, current directory is not always the same as the one in the previous tab.

[/]$ cd a
[/a]$ cd b
[/a/b]$ cd c
[/a/b/c]$
<New tab>

The new tab is opened randomly in /, /a, /a/b or /a/b/c
Comment 1 Christoph Feck 2010-02-19 00:54:36 UTC
Created attachment 40913 [details]
Proposed patch

This always annoyed me too... and you just reminded me that I should have a look at it. The problem is that currentWorkingDirectory() only returns cached information, and the cache is updated delayed.

Attached patch is only a dirty fix. The correct solution would be to add an invalidateWorkingDirectoryCache() method that just clears out the local variable, so that on next call the cache is updated.
Comment 2 Daniel Hahler 2010-05-30 03:00:58 UTC
Christoph, thanks for a solution to this.

Can you provide the (more) "correct solution" maybe, too? :)
Comment 3 Daniel Hahler 2010-05-30 03:01:39 UTC
*** Bug 189528 has been marked as a duplicate of this bug. ***
Comment 4 Daniel Hahler 2010-05-30 03:15:15 UTC
I've marked bug 189528 as duplicate, but it is not directly the same, although probably related:
Bug 189528 is about the internally saved cwd changing when you do e.g. "find /".
Doing so, waiting a few seconds and opening a new tab will get you into some very random directory.

I think Konsole should only update the current directory (used as starting point for new tabs) when a new prompt gets displayed.
During the "find" or any other long running process, it may be fine to periodically update the cwd displayed in the title bar.
However, the latter one should get updated instantly after "cd" / new prompt, too (see bug 207018).
Comment 5 Robert Knight 2010-05-31 01:24:41 UTC
> I think Konsole should only update the current directory
> (used as starting point for new tabs) when a new prompt gets displayed.

The terminal has no understanding of the output of the programs running it in so you'd need to find some suitable heuristics.

The current heuristic is very simple, whenever input is received from the user, a timer is started which expires ~2 seconds later, at which point the current working directory of the program which has control of the terminal is recorded.  The reason for the long timeout is to avoid the tab titles changing too frequently (see the Mac terminal application for an example of this problem).
Comment 6 Kurt Hindenburg 2011-03-04 20:40:01 UTC
Git commit ad9f8011c36cf86d79f8e72d027853391c94c101 by Kurt Hindenburg.
Committed on 04/03/2011 at 20:34.
Pushed by hindenburg into branch 'master'.

Correct issue where new tabs start in wrong directories.

Currently, Konsole only updates the tab folder ~2 seconds.  After this
patch, when a new tab is requested the working directory is updated.

Patch by Christoph Feck.

BUG: 227156
FIXED-IN: 4.7

M  +10   -0    src/MainWindow.cpp     

http://commits.kde.org/konsole/ad9f8011c36cf86d79f8e72d027853391c94c101
Comment 7 Kurt Hindenburg 2011-04-10 22:49:08 UTC
Git commit edec4bedbc9a3ed49d79ac31a5c3d425a47dc47b by Kurt Hindenburg.
Committed on 04/03/2011 at 20:34.
Pushed by hindenburg into branch 'KDE/4.6'.

Correct issue where new tabs start in wrong directories.

Currently, Konsole only updates the tab folder ~2 seconds.  After this
patch, when a new tab is requested the working directory is updated.

Patch by Christoph Feck.

I don't see any reason this can't go in 4.6.x

CCBUG: 227156
FIXED-IN: 4.7
(cherry picked from commit ad9f8011c36cf86d79f8e72d027853391c94c101)

M  +10   -0    src/MainWindow.cpp     

http://commits.kde.org/konsole/edec4bedbc9a3ed49d79ac31a5c3d425a47dc47b