Bug 393447 - Kleopatra uses current directory of parent process
Summary: Kleopatra uses current directory of parent process
Status: RESOLVED FIXED
Alias: None
Product: kleopatra
Classification: Applications
Component: general (show other bugs)
Version: 3.1.0
Platform: Other Microsoft Windows
: NOR normal
Target Milestone: ---
Assignee: Andre Heinecke
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-04-24 03:11 UTC by chrstphrchvz
Modified: 2018-04-24 12:36 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description chrstphrchvz 2018-04-24 03:11:21 UTC
When Kleopatra is opened (if it is not already running in the background) it will have its current directory (working directory) typically set to that of its parent process.

This means that, for example, if I open a file associated with Kleopatra from Explorer, and if Kleopatra is not already running in the background, then Kleopatra will open and perform any operations on the file, and stay open in the background when finished. However, Kleopatra's current directory will be set to the directory the file was in, even after it is finished with the file.

In turn, this leads to issues such as when launching Kleopatra by clicking a file on a removable disk, and letting Kleopatra stay open after it finishes, then Windows will complain that the "device is currently in use" if I try ejecting the disk, since there is still an open handle to a directory on the disk, and even though the Kleopatra has closed any handles to the file I opened.

I'm not sure what the general advice or trends are regarding which working directory a program should use. I'm just under the impression it isn't necessary for a program like Kleopatra to need to use the parent process' current directory since it doesn't appear to affect functionality.
Comment 1 Andre Heinecke 2018-04-24 04:31:30 UTC
Good point. For Windows it would be a good idea if Kleopatra would change the working directory on start to a generic location e.g. the users Home Dir.

We have other processes like gpg-agent we do this exactly for the reason you mention. ( https://dev.gnupg.org/T2670 )
Comment 2 Andre Heinecke 2018-04-24 12:36:12 UTC
Git commit 45058011974ecdf71aad580526c962cfb2e07c77 by Andre Heinecke.
Committed on 24/04/2018 at 12:35.
Pushed by aheinecke into branch 'master'.

Change working dir on Windows after startup

After handling the filename arguments on the command line
switch the working directory on Windows to prevent the
locking the directory from which Kleo was started
for deletion.

This is important for the file extension support
of Kleopatra on Windows.

This also unifies two return paths in newInstance to
a single one to avoid duplication.

M  +11   -3    src/kleopatraapplication.cpp

https://commits.kde.org/kleopatra/45058011974ecdf71aad580526c962cfb2e07c77