On 10/23/2012 11:26 AM, Jakub Filak wrote:
- closes rhbz#869032
Signed-off-by: Jakub Filak <jfilak(a)redhat.com>
---
src/lib/steal_directory.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/src/lib/steal_directory.c b/src/lib/steal_directory.c
index ccfdd30..b72baa5 100644
--- a/src/lib/steal_directory.c
+++ b/src/lib/steal_directory.c
@@ -102,6 +102,16 @@ struct dump_dir *open_directory_for_writing(
if (!dd)
return NULL;
+ bool dd_was_cwd = false;
+ {
+ char old_cwd[PATH_MAX + 1];
+ /* must get CWD before deleting */
+ if (getcwd(old_cwd, sizeof(old_cwd)))
+ dd_was_cwd = strcmp(old_cwd, dump_dir_name) == 0;
+ else
+ perror_msg("getcwd()");
+ }
+
/* Delete old dir and switch to new one.
* Don't want to keep new dd open across deletion,
* therefore it's a bit more complicated.
@@ -115,5 +125,10 @@ struct dump_dir *open_directory_for_writing(
if (!dd)
xfunc_die(); /* error msg was already logged */
+ /* Update CWD to the new dump dir path if CWD is the stolen dump dir */
+ /* Nonexisting CWD breaks lot of things (i.e. gnome-open can't open URL)*/
+ if (dd_was_cwd && !chdir(dd->dd_dirname))
please push it aftery you
fix !chdir
+ perror_msg("chdir()");
+
return dd;
}
--
Richard Marko