Mercurial > octave
changeset 26972:d164e70efbf6
prevent editor from closing files that are not affected by rmdir (bug #55823)
* file-editor.cc (handle_dir_remove): additionally check whether the path
of the file relative to the removed directory is the same as its absolute
one before checking the relative path for ../
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Mon, 25 Mar 2019 20:21:51 +0100 |
parents | f75882347af3 |
children | 2b23129f8a96 |
files | libgui/src/m-editor/file-editor.cc |
diffstat | 1 files changed, 15 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor.cc Mon Mar 25 19:20:09 2019 +0000 +++ b/libgui/src/m-editor/file-editor.cc Mon Mar 25 20:21:51 2019 +0100 @@ -2432,12 +2432,23 @@ if (p->first.isEmpty ()) continue; // Nothing to do, no valid file name + // Get abs. file path and its path relative to the removed directory QString rel_path_to_file = old_dir.relativeFilePath (p->first); - if (rel_path_to_file.left (3) != QString ("../")) + QString abs_path_to_file = old_dir.absoluteFilePath (p->first); + + // Test whether the file is located within the directory that will + // be removed. For this, two conditions must be met: + // 1. The path of the file rel. to the dir is not equal to the + // its absolute one. + // If both are equal, then there is no relative path and removed + // directoy and file are on different drives (e.g.on windows) + // 2. The (real) relative path does not start with "../", i.e., + // the file can be reached from the directory by descending only + if ((rel_path_to_file != abs_path_to_file) + && (rel_path_to_file.left (3) != QString ("../"))) { - // We directly go down from old_dir to reach our file: Our - // file is included in the removed/renamed diectory. - // Thus delete it. + // The currently considered file is included in the + // removed/renamed diectory: Delete it. m_no_focus = true; // Remember for not focussing editor file_editor_tab *editor_tab = static_cast<file_editor_tab *> (p->second.fet_ID);